Is it possible in XAML
to define multiple Run
's inside a Style
setter?
The following has two Run
's defined and fails:
The property 'Value' is set more than once.
<TextBlock>
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Text">
<Setter.Value>
<Run Text="{Binding SelectedItem.iso}"/>
<Run Text="{Binding SelectedItem.value}"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedItem.type}" Value={x:Null}">
<Setter Property="Text" Value="No value" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
Can this be fixed while preserving the usage of multiple Run
's?
A Setter works on one property, so it can have only one value, the error you get is logical: it has no way of understanding what you're trying to do, it can just... set a property to a given value.
So the idea is to give it this value as it should be: appended texts. To do so, you would use MultiBinding, which takes multiple values and returns them as one, depending on the StringFormat you give it:
<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>
Note on StringFormat: You have to use {}
at start to escape braces, else it would consider them as markup extension starters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With