ygoe / TxTranslation

Tx Translation & Localisation for .NET and WPF
GNU General Public License v3.0
28 stars 12 forks source link

How to translate texts in WPF DataTrigger Setters? #8

Closed pinki closed 7 years ago

pinki commented 7 years ago

Hi, is there a way to use TxTranslation inside DataTrigger Setters?

ygoe commented 7 years ago

Can you show an example of your XAML code, please?

pinki commented 7 years ago

Sure!

<TextBlock VerticalAlignment="Center">
    <TextBlock.Style>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="Text" Value="My first text"/>

            <Style.Triggers>
                <DataTrigger Binding="{Binding Switch.IsEnabled, Mode=OneWay}" Value="True">
                    <Setter Property="Text" Value="My second text"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>

The markup extension neither works in the first nor in the second setter.

ygoe commented 7 years ago

I haven't tried that yet. Does the usual method not work? Maybe you need to use a more complex syntax with a separate <Setter.Value><Tx:T …/></Setter.Value> element or similar.

ygoe commented 7 years ago

You can use it as normal. Visual Studio will underline the XAML with blue colour and say that TExtension is not allowed for Setter.Value, but it will run and work as expected anyway. It's not uncommon that the WPF designer calls out errors where there are none at runtime. It's annoying but works.