Mã này làm việc (khi ControlType = "thả xuống", sau đó nền vàng):Làm cách nào để chuyển đổi chế độ hiển thị của TextBlock trong DataTrigger?
<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>
Nhưng mã này không không làm việc (khi ControlType = "thả xuống", sau đó TextBlock vẫn là vô hình):
<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>
tại sao tôi không thể thiết lập tầm nhìn trong một phong cách như tôi có thể nền?
tôi bị buộc phải sai lầm này 10 lần trước khi nó chìm trong –
Yeah, tôi quá.. Bây giờ, đây là điều đầu tiên tôi tìm kiếm khi xem xét mã bằng Trình kích hoạt. –
chính xác là vấn đề, cảm ơn –