根据ComboBox选择使按钮可见 [英] Make Button Visible Based on ComboBox selection
本文介绍了根据ComboBox选择使按钮可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果使用XAML在ComboBox中选择了某个值,如何显示Button?
How do I make a Button show if a certain value is selected in a ComboBox using XAML ?
这就是我的尝试。
谢谢
<ComboBox x:Name="ComboBox" Margin="171,102,426,271">
<ComboBoxItem>Testing</ComboBoxItem>
<ComboBoxItem>Again</ComboBoxItem>
<ComboBoxItem>Finally</ComboBoxItem>
</ComboBox>
<Button Margin="10, 0, 0, 0" >
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBox}" Value="Testing">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
推荐答案
您正在测试您的风格中的SelectedIndex。 对SelectedIndex进行测试,并在测试中使用0或对SelectedValue进行测试。
You are testing for the SelectedIndex in your style. Either test against the SelectedIndex and use 0 in the test or test against SelectedValue.
这篇关于根据ComboBox选择使按钮可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文