WPF TextBlock Trigger Question
-
I am trying to hide a text block. When a Checkbox is checked, it should be hidden. When it's unchecked the textblock should be visible. The checkbox is bound to an object called SelectedProcess. If SelectedProcess is null, the textblock should be hidden. Here's my XAML:
<Style.Triggers> <DataTrigger Binding="{Binding SelectedProcess}" Value="Null"> <Setter Property="UIElement.Visibility" Value="Hidden"/> </DataTrigger> <DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="True"> <Setter Property="UIElement.Visibility" Value="Hidden"/> </DataTrigger> <DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="False"> <Setter Property="UIElement.Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers>
It works when SelectedProcess is NOT null, but when SelectedProcess IS null, the text is still visible. What am I doing wrong here? Thanks
If it's not broken, fix it until it is
-
I am trying to hide a text block. When a Checkbox is checked, it should be hidden. When it's unchecked the textblock should be visible. The checkbox is bound to an object called SelectedProcess. If SelectedProcess is null, the textblock should be hidden. Here's my XAML:
<Style.Triggers> <DataTrigger Binding="{Binding SelectedProcess}" Value="Null"> <Setter Property="UIElement.Visibility" Value="Hidden"/> </DataTrigger> <DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="True"> <Setter Property="UIElement.Visibility" Value="Hidden"/> </DataTrigger> <DataTrigger Binding="{Binding SelectedProcess.Enabled}" Value="False"> <Setter Property="UIElement.Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers>
It works when SelectedProcess is NOT null, but when SelectedProcess IS null, the text is still visible. What am I doing wrong here? Thanks
If it's not broken, fix it until it is
Try
Value="{x:Null}"
instead. http://msdn.microsoft.com/en-us/library/ms743649%28v=vs.110%29.aspx[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Try
Value="{x:Null}"
instead. http://msdn.microsoft.com/en-us/library/ms743649%28v=vs.110%29.aspx[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
That did it. Thank you!
If it's not broken, fix it until it is
-
That did it. Thank you!
If it's not broken, fix it until it is
Your issue seems fixed, which is great. However, I wonder why you use datatriggers to accomplish this. Consider doing it through binding instead with the help of a converter. If the visibility of the texblock is always directly related to the checkbox being checked / unchecked, then you could use elementbinding to do so.
The resulting XAML is simpler and achieves the same result.