我是 WPF 的新手,我试图创建 xaml 逻辑来显示/隐藏基于 ViewModel 上 AllowMiscTitle 的值的控件。The xaml consist of two fields a combobox of the standard tiles ("Mr", "Mrs", ..., "Other") when "Other" is selected I want the textbox to display.
我创建了以下 xaml:
<DockPanel Validation.Error="Validation_Error" HorizontalAlignment="Stretch">
<ComboBox ItemsSource="{Binding Path=Titles, Mode=OneTime}"
Text="{Binding Path=Title}"/>
<TextBox x:Name="TxtBxTitle" Margin="5,5" Visibility="Visible">
<TextBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=AllowMiscTitle}" Value="false">
<Setter Property="TextBox.Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</DockPanel>