.NET Framework Developer Center >
.NET Development Forums
>
Windows Presentation Foundation (WPF)
>
Control.Tag ,Triggers and custom class
Control.Tag ,Triggers and custom class
- Hi,
Until now I used a simple tag on a textbox to change its appearance
e.g.
<Trigger Property="Tag" Value="Stuff">
<Setter Property="BorderBrush" TargetName="Border" Value="#FF0000"/>
</Trigger>
Now the problem grew slighty more complex and I need cram more data into that tag.
e.g.
public class ExtendedTagInfo {
public string Info {get;set;}
public string MoreInfo {get;set;}
}
It works fine in 'normal' code but then there's this pesky trigger.
<Trigger Property="Tag.Info" Value="Stuff">
won't compile.
This is small part of a huge project and sadly I think I'd get into serious trouble if I just go ahead and create a special user control that suits my needs. The textbox style in question is used hundreds of times all over the project.
Any idea on how to get this thing to work "in style"?
TIA
Answers
- Hi,
Use Data Trigger and bind to the Tag property
<TextBox Height="23" Margin="81,60,77,0" Name="TextBox1" VerticalAlignment="Top" > <TextBox.Style> <Style TargetType="{x:Type TextBox}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Info}" Value="Yes" > <Setter Property="Background" Value="Red"/> </DataTrigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox>Hope it helps
Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem- Marked As Answer byJulchen Wednesday, November 04, 2009 12:04 PM
All Replies
- Hi,
Use Data Trigger and bind to the Tag property
<TextBox Height="23" Margin="81,60,77,0" Name="TextBox1" VerticalAlignment="Top" > <TextBox.Style> <Style TargetType="{x:Type TextBox}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Info}" Value="Yes" > <Setter Property="Background" Value="Red"/> </DataTrigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox>Hope it helps
Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem- Marked As Answer byJulchen Wednesday, November 04, 2009 12:04 PM


