Created
October 17, 2011 01:47
-
-
Save dancrowley303/1291751 to your computer and use it in GitHub Desktop.
style trigger for zero length textbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Would like to have a xaml (view) only method to change the textbox text to "Search ..." when the textbox is empty. | |
My xaml file has this: | |
<TextBox Name="searchBox" Text="{Binding Path=TextFilter, UpdateSourceTrigger=PropertyChanged}"/> | |
<TextBox.Style> | |
<Style TargetType="{x:Type TextBox}"> | |
<Style.Triggers> | |
<DataTrigger Binding="Text.Length, {Binding RelativeSource={RelativeSource = Self}}" Value="0"> | |
<Setter Property="Text" Value="Search ..." /> | |
</DataTrigger> | |
</Style.Triggers> | |
</Style> | |
</TextBox.Style> | |
</TextBox> | |
TextFilter is a string property that may be empty or have a value. | |
On execution, this error is thrown: | |
{"'Set property 'System.Windows.DataTrigger.Binding' threw an exception.' Line number '24' and line position '34'."} | |
Unable to cast object of type 'System.String' to type 'System.Windows.Data.BindingBase'. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment