Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

reusing Resx instances

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Globalizer Support
View previous topic :: View next topic  
Author Message
eduardo



Joined: 19 Jun 2012
Posts: 3

PostPosted: Thu Jul 26, 2012 11:02 pm    Post subject: reusing Resx instances Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Jul 27, 2012 9:45 am    Post subject: Reply with quote

The way Style Setter properties are designed means that it is not possible to use Resx Extension with them and support dymanic language changing.

See the following thread on code project for more information:

http://www.codeproject.com/Articles/35159/WPF-Localization-Using-RESX-Files?msg=4200417#xx4200417xx
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
eduardo



Joined: 19 Jun 2012
Posts: 3

PostPosted: Tue Jul 31, 2012 3:51 pm    Post subject: Resx and DataTriggers Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Jul 31, 2012 10:56 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Globalizer Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group