此代码有效(当 ControlType="dropDown" 然后背景黄色):
<Window x:Class="TestCollapsed.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:TestCollapsed.Commands"
Title="Main Window" Height="400" Width="800">
<Window.Resources>
<Style x:Key="DropDownStyle" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding ControlType}" Value="dropDown">
<Setter Property="Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<TextBlock Visibility="Visible"
Text="This is going to be the dropdown control."
Style="{StaticResource DropDownStyle}"/>
</StackPanel>
</Window>
但是这段代码不起作用(当 ControlType="dropDown" 那么 TextBlock 仍然是不可见的):
<Window x:Class="TestCollapsed.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:TestCollapsed.Commands"
Title="Main Window" Height="400" Width="800">
<Window.Resources>
<Style x:Key="DropDownStyle" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding ControlType}" Value="dropDown">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<TextBlock Visibility="Collapsed"
Text="This is going to be the dropdown control."
Style="{StaticResource DropDownStyle}"/>
</StackPanel>
</Window>
为什么我不能像背景一样设置样式的可见性?