码迷,mamicode.com
首页 > Windows程序 > 详细

WPF 之 利用Visibility属性进行Item模板切换

时间:2016-05-23 10:26:13      阅读:796      评论:0      收藏:0      [点我收藏+]

标签:

  前台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
     }

 

WPF 之 利用Visibility属性进行Item模板切换

标签:

原文地址:http://www.cnblogs.com/xinaixia/p/5518813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!