我有一个简单的 XAML,如下所示:
<Window.Resources>
<Converters:ButtonVisibilityConverter x:Key="m_ButtonConverter"/>
</Window.Resources>
<Grid>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="71,18,0,0" Name="comboBox1" VerticalAlignment="Top" Width="229" SelectionChanged="comboBox1_SelectionChanged">
</ComboBox>
<TextBox Height="23" HorizontalAlignment="Left" Margin="71,76,0,0" Name="textBox1" VerticalAlignment="Top" Width="229" Style="{StaticResource requiredFieldValidationStyle}"/>
<TextBox Height="23" HorizontalAlignment="Left" Margin="71,125,0,0" Name="textBox2" VerticalAlignment="Top" Width="229" Style="{StaticResource requiredFieldValidationStyle}"/>
<Button Content="Submit" Height="23" HorizontalAlignment="Left" Margin="225,175,0,0" Name="button1" VerticalAlignment="Top" Width="75">
<Button.IsEnabled>
<MultiBinding Converter="{StaticResource m_ButtonConverter}">
<Binding ElementName="textBox1" Path="Text" />
<Binding ElementName="textBox2" Path="Text" />
<Binding ElementName="comboBox1" Path="Text" />
</MultiBinding>
</Button.IsEnabled>
</Button>
<Label Content="Box 1" Height="28" HorizontalAlignment="Left" Margin="12,74,0,0" Name="label1" VerticalAlignment="Top" />
<Label Content="Box 2" Height="28" HorizontalAlignment="Left" Margin="12,123,0,0" Name="label2" VerticalAlignment="Top" />
</Grid>
textbox1 和 textbox2 现在都是必填字段,除非两个框都有文本,否则该按钮不会启用。
我想做以下事情:在组合框中选择偶数时,我想将 textbox2 条目设为可选。这意味着,我将它从(按钮的 IsEnabled 的)多重绑定中删除,并且还删除了样式。However, when an odd number is chosen, I want them back.
有人可以帮忙吗?