关于WPF使用MultiConverter控制Button状态的详细介绍 |
需求描述 按钮XAML 复制代码 代码如下: <Button Name="btnOK" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Command="{Binding Path=OKCommand}" Content="{DynamicResource Common_Button_OK}" IsDefault="True" Style="{DynamicResource ButtonStyle}"> <Button.IsEnabled> <MultiBinding Converter="{StaticResource InvalidMultiValidationRuleToBooleanMultiConverter}" ConverterParameter="objectnull|greaterthanzerointeger|greaterthanzerointeger|greaterthanzerointeger"> <Binding ElementName="comboBoxFilter" Mode="OneWay" Path="SelectedItem" /> <Binding ElementName="textBoxFrameRate" Mode="OneWay" Path="Text" /> <Binding ElementName="textBoxSizeWidth" Mode="OneWay" Path="Text" /> <Binding ElementName="textBoxSizeHeight" Mode="OneWay" Path="Text" /> </MultiBinding> </Button.IsEnabled> </Button> MultiConverter判断 复制代码 代码如下: public class InvalidMultiValidationRuleToBooleanMultiConverter : IMultiValueConverter { #region IMultiValueConverter Members public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) IList<bool> boollist = new List<bool>(); for (int i = 0; i < paramlist.Length; i++) bool result = boollist[0]; return result; public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) #endregion |