View previous topic :: View next topic |
Author |
Message |
eduardo
Joined: 19 Jun 2012 Posts: 3
|
Posted: Thu Jul 26, 2012 11:02 pm Post subject: reusing Resx instances |
|
|
I was 'playing' with the style below, which is for a filter's watermark, that has variable content depending on the value of other filters. So:
IF showAllContacts THEN "Last Name / Company Name"
ELSEIF showOnlyPeople THEN "Last Name"
ELSE "Company Name".
And of course, use Globalizer / Resx to translate the display on the fly!
I was wondering if I could define the LastName & Company Name as resources once and then reuse them.
The xaml below works, at least in the starting culture. As you can see I am using the Resx instances in the DataTriggers, but I couldn't figure out how to replace that MultiBinding with them.
Is there a way to do this? Can I expect it to translate on the fly if so? I know you have made some changes to the product to get around previous limitation with Setters but I am just too thick to have absorbed it from existing docs and questions yet!
Cheers
Code: | <resx:Resx x:Key="personRequiredName" ResxName="Resources.PimShellView" Key="Filter_ByName_RequiredPart_LastName" />
<resx:Resx x:Key="orgRequiredName" ResxName="Resources.PimShellView" Key="Filter_ByName_RequiredPart_CompanyName" />
<!--
Defines a search box that changes it's watermark (label text) according to the type of filterByType applied
-->
<Style x:Key="RequiredNameFilter" TargetType="{x:Type cc:SearchTextBox}" BasedOn="{StaticResource SearchTextBoxStyle}">
...
<Setter Property="LabelText">
<Setter.Value>
<MultiBinding StringFormat="{}{0} / {1}">
<Binding Source="{resx:Resx ResxName=Resources.PimShellView, Key=Filter_ByName_RequiredPart_LastName}"/>
<Binding Source="{resx:Resx ResxName=Resources.PimShellView, Key=Filter_ByName_RequiredPart_CompanyName}"/>
</MultiBinding>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ShowOnlyPeople}" Value="true">
<Setter Property="LabelText" Value="{StaticResource personRequiredName}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ShowOnlyOrganizations}" Value="True">
<Setter Property="LabelText" Value="{StaticResource orgRequiredName}"/>
</DataTrigger>
</Style.Triggers>
</Style> |
|
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
|
Back to top |
|
|
eduardo
Joined: 19 Jun 2012 Posts: 3
|
Posted: Tue Jul 31, 2012 3:51 pm Post subject: Resx and DataTriggers |
|
|
Thanks for the quick reply.
Does this mean you cannot use resx with DataTriggers?
If so, is there a recommended work around? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jul 31, 2012 10:56 pm Post subject: |
|
|
I don't think you will be able to use the resx extension with DataTriggers. I would suggest looking at using a BindingConverter instead. If you can define an enum Filter type eg
Code: | enum FilterType
{
All,
OnlyPeople,
OnlyOrganizations
} |
And a property on your data that is set to this enum then you could bind to it using a converter derived from ResourceEnumConverter. This converts enum values into text values using the resources. You can then use the converter within the Resx. The following example is from the WPF Sample Project which binds a text block to an enum value selected in another control using a converter:
Code: | <TextBlock Name="_selectedTextBlock">
<TextBlock.Text>
<Resx Key="_selectedTextBlock.Text"
BindingElementName="_fileListBox"
BindingPath="SelectedItem"
BindingConverter="{StaticResource sampleEnumConverter}" />
</TextBlock.Text>
</TextBlock> |
_________________ Infralution Support |
|
Back to top |
|
|
|