I need to set the tabstop of a textbox based on whether or not the bound property has data or not. The properties are nearly all strings - I want to disable the tabstop if the property is null or empty.
I am using a style for these textboxes.
Here is the style I am currently using:
<Style TargetType="TextBox" x:Key="FauxLabel">
<Setter Property="Background" Value="Transparent" />
<Setter Property="IsTabStop" Value="True" />
<Setter Property="IsReadOnly" Value="True" />
<!-- rest of setters truncated -->
</Style>
And here is an example of my usage:
<TextBox
Name="Account"
Style="{StaticResource ResourceKey=FauxLabel}"
Text="{Binding
Path=SelectedItem.AccountNumber,
ElementName=CrfResults}"/>
In this exmple, if the AccountNumber property is null or empty, I want to disable the tabstop. I am using Visual Studio 2010 and .Net 4.0. Can anyone help me out?
Update:
Thanks to Rachel for her answer. I was able to update the style to h开发者_C百科andle all textboxes using that style using by adding the trigger below which binds to the text property, rather than the underlying bound property:
<Style.Triggers>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="IsTabStop" Value="False">
</Setter>
</Trigger>
<Trigger Property="Text" Value="">
<Setter Property="IsTabStop" Value="False">
</Setter>
</Trigger>
</Style.Triggers>
Use a DataTrigger which checks if the value is {x:Null}
<Style TargetType="TextBox" x:Key="FauxLabel">
<Setter Property="IsTabStop" Value="True" />
<Style.Triggers>
<DataTrigger Property="{Binding ElementName=CrfResults, Path=SelectedItem.AccountNumber}" Value="{x:Null}">
<Setter Property="IsTabStop" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
You could probably do it with a regular Trigger instead of a DataTrigger too
精彩评论