WPF MVVM 绑定RadioButton数据

一、 M层,创建实体

    public class NotificationBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    [DataContract]
    public abstract class BaseModel : NotificationBase
    {

    }

    [DataContract]
    public class BuildProductsModel : BaseModel
    {

        /// 
        /// 是否翻转
        /// 
        private string isreversal;
        [DataMember]
        public string IsReversal
        {
            get { return isreversal; }
            set
            {
                isreversal = value;
                NotifyPropertyChanged("IsReversal");
            }
        }

    }

二、VM层

    public class PageBuildProductsModel : BaseModel
    {
        public BuildProductsModel ProductsModel { get; set; }
        public PageBuildProductsModel()
        {
            ProductsModel = new BuildProductsModel();
            ProductsModel.IsReversal = "翻转";
        }
    }


三、V层

    public partial class Page_BuildProducts : Page
    {
        public Page_BuildProducts()
        {
            InitializeComponent();
            this.DataContext = new PageBuildProductsModel();
        }
    }



    
        
    
    
        
            
            
        

    
    public class EnumToBooleanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value == null ? false : value.Equals(parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value != null && value.Equals(true) ? parameter : Binding.DoNothing;
        }
    }




你可能感兴趣的:(WPF/Blend)