I have the need to write part of the text inside a button with a different foreground. Until now, following this solution, i was using the following piece of code:
<Button>
<TextBlock Margin="20"
FontSize="24"
FontStyle="Normal"
FontWeight="Medium"
Foreground="#FF1384F5">
<Run>text1</Run>
<Run Foreground="#FF1372D3" Text="{Binding MyBinding}"/>
<Run >text2</Run>
</TextBlock>
</Button>
now i have the need to change the whole text based on a trigger, so i builded a DataTriger like the following:
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding MyBoolean}" Value="True">
<Setter Property="Text">
<Setter.Value>
<Run>text1</Run>
<Run Foreground="#FF1372D3" Text="{Binding MyBinding}"/>
<Run >text2</Run>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding MyBoolean}" Value="False">
<Setter Property="Text" Value="text3" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
of course this doesn't work because the property value is setted more than once. Looking for a solution i found this . It basically says to use multi binding
<Setter.Value>
<MultiBinding StringFormat="{}{0}{1}{2}"><!-- Format as you wish -->
<Binding Path="SelectedItem.iso"/>
<Binding Source="{x:Static System:Environment.NewLine}"/>
<Binding Path="SelectedItem.value"/>
</MultiBinding>
</Setter.Value>
But i'm not sure if it fit my situation, and how to use it eventually.