Bind TextBlock.Text in a Style by DataTrigger [modified]
-
Hi folks! Anyone please can help me with this:
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsDevice}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<TextBlock x:Name="txt"></TextBlock>
<StackPanel.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=PositionDevice}" Value="0">// HERE I WOULD NEED SOMETHING LIKE THIS:
<Setter Property="{Binding Path=Text, ElementName=txt}" Value="TEST"/>
//WHICH IS NOT WORKING</DataTrigger>
Thank you in advance!
modified on Sunday, September 13, 2009 6:42 PM
-
Hi folks! Anyone please can help me with this:
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsDevice}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<TextBlock x:Name="txt"></TextBlock>
<StackPanel.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=PositionDevice}" Value="0">// HERE I WOULD NEED SOMETHING LIKE THIS:
<Setter Property="{Binding Path=Text, ElementName=txt}" Value="TEST"/>
//WHICH IS NOT WORKING</DataTrigger>
Thank you in advance!
modified on Sunday, September 13, 2009 6:42 PM
I believe you are looking for the TargetName property of the Setter.
<Setter TargetName="txt" Property="Text" Value="TEST" />
-
I believe you are looking for the TargetName property of the Setter.
<Setter TargetName="txt" Property="Text" Value="TEST" />
-
Error 1 TargetName property cannot be set on a Style Setter Thank you for your hint, unfortunately it's not working. Any other ideas maybe?
Since the trigger does not seem like it really needs to be inside the style (from what I can see here), I would suggest moving the trigger into the ControlTemplate's trigger collection instead.
-
Since the trigger does not seem like it really needs to be inside the style (from what I can see here), I would suggest moving the trigger into the ControlTemplate's trigger collection instead.