前台Xaml如下:
<Grid.Resources> <xx:AccountStatusToVisibility x:Key="AccountStatusToVisibility" /> </Grid.Resources> <telerik:RadButton Visibility="{Binding Status, Mode=OneWay, Converter={StaticResource AccountStatusToVisibility}, ConverterParameter=Disabled}" Margin="0 0 5 0" Click="RadButton_Click" Command="{Binding Path=DataContext.CmdDisabled, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}" >设置启用</telerik:RadButton>
后台,模板切换类:
public class AccountStatusToVisibility : IValueConverter { #region "IValueConverter Members" public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return false; } if (parameter != null) { switch (parameter.ToString()) { case "Enabled": return ((int)value == 0) ? Visibility.Collapsed : Visibility.Visible; case "Disabled": return ((int)value == 1) ? Visibility.Collapsed : Visibility.Visible; //case "Invaild": // return ((int)value == 2) ? Visibility.Collapsed : Visibility.Visible; } } return false; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion }
时间: 2024-11-05 22:45:33