Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion docs/Localize.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ the extensions support to add the Binding as Constructor. Because of WPF restric
{lex:Loc {Binding Path=Foo}}
```

or via content

```xaml
<lex:Loc>
<Binding Path="Foo" "/>
</lex:Loc>
```

Multibinding only possible via content please use the following syntax:

```xaml
<lex:Loc>
<MultiBinding Converter="FooAndBarConverter">
<Binding Path="Foo" "/>
<Binding Path="Bar" "/>
</MultiBinding>
</lex:Loc>
```

This gives you the full flexibility because the Markupextensions is the pure Binding and this supports Converters, StringFormat, ...

### Enums
Expand Down Expand Up @@ -89,6 +108,6 @@ For translation of complex texts there some value should be in the text like thi

>You have selected 10 car(s).

TWe have introduces a StringFormatConverter see [ValueConverters](ValueConverters.md) with automatic using of [smartFormat](https://github.com/axuno/SmartFormat) if this is available.
We have introduced a StringFormatConverter see [ValueConverters](ValueConverters.md) with automatic using of [smartFormat](https://github.com/axuno/SmartFormat) if this is available.
A detailed explanation how to use can be found [here](GapText.md).

10 changes: 5 additions & 5 deletions src/Extensions/LocExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal void OnNotifyPropertyChanged(string property)
/// <summary>
/// Holds the Binding to get the key
/// </summary>
private Binding _binding;
private BindingBase _binding;

/// <summary>
/// the Name of the cached dynamic generated DependencyProperties
Expand Down Expand Up @@ -259,10 +259,10 @@ public object ConverterParameter
/// Gets or sets the Key that identifies a resource (Assembly:Dictionary:Key)
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public object ResourceIdentifierKey
public BindingBase ResourceIdentifierKey
{
get => _key ?? "(null)";
set => _key = value.ToString();
get => _binding;
set => _binding = value;
}
#endregion

Expand Down Expand Up @@ -298,7 +298,7 @@ public LocExtension(object key)
key = newBinding;
}

if (key is Binding binding)
if (key is BindingBase binding)
_binding = binding;
else
Key = key?.ToString();
Expand Down
9 changes: 9 additions & 0 deletions tests/HelloWorldWPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@
</Button.Template>
</Button>
<TextBlock Text="{lex:Loc {Binding tenum, StringFormat=TestEnum_{0}}}"></TextBlock>
<TextBlock>
<TextBlock.Text>
<lex:Loc>
<MultiBinding StringFormat="{}{0}">
<Binding Path="tenum" StringFormat="TestEnum_{0}"/>
</MultiBinding>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not work as expected. I think it shold be like that:

<MultiBinding StringFormat="{}TestEnum_{0}">
    <Binding Path="tenum" />
</MultiBinding>

Explanation
And yes, my version looks weird :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not work as expected. I think it shold be like that:

<MultiBinding StringFormat="{}TestEnum_{0}">
    <Binding Path="tenum" />
</MultiBinding>

Explanation
And yes, my version looks weird :)

@Karnah
I change the example to avoid this MultiBinding StringFormat Bug. Thanks for the Explanation.

</lex:Loc>
</TextBlock.Text>
</TextBlock>
<TextBlock Text="{lex:Loc {Binding tenum, Converter={lex:PrependTypeConverter}, ConverterParameter=__}}"></TextBlock>
<Button Name="BindeTestButton" Content="Press to toggle binded property" Margin="5" Click="BindeTestButton_Click" ></Button>
<TextBlock Name="MyLabel2" FontSize="20" Text="{lex:Loc PresentationCore:ExceptionStringTable:DeleteText}" HorizontalAlignment="Center" />
Expand Down