Like to to use lex:LocText with resource key returned by converter
schwartzberg opened this issue · 4 comments
Like to to use lex:LocText with resource key returned by a converter
Something like this:
Text="{lex:Loc {Binding Path=Name, Converter={StaticResource EnumToLocalizedDescriptionConverter}}}" />
-- but the above doesnt work. Pls inform me if there is a syntax that does so.
-- or it is not possible yet to do what i am asking.
This was also asked here, with a real answer to be desired:
*** https://stackoverflow.com/questions/9176462/use-converter-with-wpf-localization-extension
But they do write in the link above that WPFLocalizationExtension can do it since version 2.1
But I have found no examples showing this.
To clarify down below is my XAML. Here is my explanation.
We see two examples in the below XAML.
(a) Text="{lex:Loc Administration_ActiveUsers_Title_Profiles}" />
Here the resource key (Administration_ActiveUsers_Title_Profiles) is hard coded in the xaml markup. This is fine.
We use it a lot.
But now we need the resource key to be returned by a converter, since the bound source is an enum value with a DescriptionAttribute which has the resource key.
(b) In the GroupStyle.HeaderTemplate.DataTemplate (more below in the Xaml) we are setting some text in a text box. Like this:
Text="{Binding Path=Name, Converter={StaticResource EnumToLocalizedDescriptionConverter}}" />
Here the source "Name" is an enum value with a DescriptionAttribute.
The converter here is returning the resource key through the DescriptionAttribute.
I would like to use it with lex:Loc or lex:LocText. In the Xaml markup.
Yes - the converter itself could return also the resource name -- but then dynamically changing the localized culture will not work here since the converter is only activated when the data is loaded for the first time): - Therefore better to do it in the XAML.
If this is already working please send me an example of the syntax.
I tried variations (trying to guess it) like here:
Text="{lex:Loc {Binding Path=Name, Converter={StaticResource EnumToLocalizedDescriptionConverter}}}" />
without success.
Code
<StackPanel
x:Name="StackPanel_UserProfilesHeader"
Grid.Row="1"
Grid.Column="0"
Style="{StaticResource FieldsetSubHeaderStackPanel}">
<Grid Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Style="{StaticResource 'Textblock As Fieldset Title'}"
Text="{lex:Loc Administration_ActiveUsers_Title_Profiles}" />
</Grid>
</StackPanel>
<!-- Selected user profiles -->
<ItemsControl
Grid.Row="2"
Margin="0,16,0,0"
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Source={StaticResource GroupedUserProfileCollectionView}}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ItemsControl.GroupStyle>
<!-- lex:LocText Key={StaticResource EnumToLocalizedDescriptionConverter} {Binding Path=Name, Converter={StaticResource EnumToLocalizedDescriptionConverter}} -->
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock
Margin="15,20,0,5"
FontFamily="{StaticResource SourceSansPro-Semibold}"
FontSize="16"
FontWeight="Bold"
Text="{Binding Path=Name, Converter={StaticResource EnumToLocalizedDescriptionConverter}}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ItemsControl.GroupStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type shared:UserProfileGridItem}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<CheckBox
Grid.Column="0"
Margin="8,0,8,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AutomationProperties.AutomationId="{Binding First.AutomationId}"
Content="{Binding First.Name}"
IsChecked="{Binding First.IsSelected, Mode=OneWay}"
IsEnabled="False"
Style="{StaticResource SBERCheckBoxStyle}" />
<CheckBox
Grid.Column="1"
Margin="8,0,8,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AutomationProperties.AutomationId="{Binding Second.AutomationId}"
Content="{Binding Second.Name}"
IsChecked="{Binding Second.IsSelected, Mode=OneWay}"
IsEnabled="False"
Style="{StaticResource SBERCheckBoxStyle}"
Visibility="{Binding Second.Id, Converter={converters:SmartBoolConditionToVisibilityConverter CompareValue={x:Null}, Comparer='!=', FalseVisibility=Hidden}}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</ScrollViewer>
@schwartzberg Hi this should work at least with the preRelease. I will take care and give you latest next week an answer
Hi,
I think this line show that this is working in the next release. You can already try the preReleases or compile from code:
you can even use a Converter in the lex:Loc and another converter in the Binding.
bye
I will try it ... in a demo project ...
I would like to ask if this issue about strong naming of the dlls in some versions of WPFLocalizationExtension still exist?
Here it is described
#225
WPFLocalisationExtension in our case is in a click-once application and (i think) it is easiest if it is all strongly named
Otherwise we cannot upgrade to the next release as you suggest.
Thanks,
Paul
@schwartzberg the issue for click-once is still exiting #260
Please at least test if this solves your issue and we are also working on a general signing solution.