LocExtension with Binding
Posted: 19 Feb 2024, 18:30
Hello,
I'm trying to use LocExtension provided by Noesis and I've encountered that I cannot dynamically bind properties to this extension, something like this: Text="{noesis:Loc {Binding WorldsText}}"
I have tried to extend this class with Binding property, but then I've encountered a few issues:
Sample usage in ComboBox:
Resource dictionary:
Is there and other way of doing this?
Thanks for answers!
I'm trying to use LocExtension provided by Noesis and I've encountered that I cannot dynamically bind properties to this extension, something like this: Text="{noesis:Loc {Binding WorldsText}}"
I have tried to extend this class with Binding property, but then I've encountered a few issues:
- Calling BindingOperations.SetBinding(...);, then targetObject.GetValue(targetProperty) will always return null, which then I tried to fix with a converter
- Above problem was fixed with a workaround to use converter inside binding, but then DependencyObject for items inside combobox item template always returns the same reference between different items, which means changing one property value via TargetObject.SetValue will change all of them
Sample usage in ComboBox:
Code: Select all
<ComboBox
ItemsSource="{Binding Source={providers:EnumItemsSourceProvider EnumType={x:Type enums:DummyEnum}}}"
SelectedItem="{Binding SelectedDummyEnum}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center"
Text="{noesis:Loc Binding={Binding .}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Code: Select all
<sys:String x:Key="FirstEnum">Translate First Enum</sys:String>
<sys:String x:Key="SecondEnum">Translate Second Enum</sys:String>
<sys:String x:Key="ThirdEnum">Translate Third Enum</sys:String>
Thanks for answers!