WPF MVVM 绑定RadioButton数据
来源:互联网 发布:淘宝推广教程视频 编辑:程序博客网 时间:2024/06/05 14:49
一、 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 { /// <summary> /// 是否翻转 /// </summary> 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 = "翻转"; } }
public partial class Page_BuildProducts : Page { public Page_BuildProducts() { InitializeComponent(); this.DataContext = new PageBuildProductsModel(); } }
<Page x:Class="AutomaticConfigurationAPP.Pages.Page_BuildProducts" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:AutomaticConfigurationCore.Commons;assembly=AutomaticConfigurationCore" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="600"> <Page.Resources> <local:EnumToBooleanConverter x:Key="EnumToBooleanConverter" /> </Page.Resources> <Grid Margin="5" x:Name="grid1"> <WrapPanel Grid.Column="3" Grid.Row="2" VerticalAlignment="Center"> <RadioButton Content="翻转" Margin="0,0,10,0" IsChecked="{Binding Path=ProductsModel.IsReversal,Mode=TwoWay,Converter={StaticResource EnumToBooleanConverter},ConverterParameter=翻转}"/> <RadioButton Content="不翻转" Margin="0,0,10,0" IsChecked="{Binding Path=ProductsModel.IsReversal,Mode=TwoWay,Converter={StaticResource EnumToBooleanConverter},ConverterParameter=不翻转}"/> </WrapPanel> </Grid></Page>
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; } }
阅读全文
0 0
- WPF MVVM 绑定RadioButton数据
- 【WPF】MVVM前台绑定一组RadioButton按钮
- WPF MVVM 绑定ComboBox数据
- WPF+MVVM数据绑定问题集锦
- WPF+MVVM数据绑定问题集锦
- WPF-MVVM双向绑定
- wpf 在MVVM模式下开发时,怎样让一个属性绑定到多个RadioButton上
- Mvvm Light Toolkit for wpf/silverlight系列之数据绑定
- Mvvm Light Toolkit for wpf/silverlight系列之数据绑定
- WPF使用MVVM完成DataGrid数据绑定带全选
- WPF与MVVM的实现(二)数据绑定
- wpf数据绑定——radiobutton绑定枚举值并显示枚举值
- MVVM数据绑定
- vue MVVM数据绑定
- 关于WPF RadioButton和CheckBox绑定问题
- WPF MVVM DataGird 数据分页
- WPF--MVVM之DataGrid数据源绑定
- MVVM WPF 使用 datagrid 绑定 comboBox
- 解决Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds.问题
- 自己动手写一个依赖注入框架
- Hibernate(四)一对多映射 补充三:双向多对一关系(学生-->班级)
- 欢迎使用CSDN-markdown编辑器
- spring生成代理对象的过程(AOP切面)
- WPF MVVM 绑定RadioButton数据
- 使用Struts2,但仅仅想返回json数据的方法
- java-随机数Math.random()
- 【effective java读书笔记】通用程序设计(二)
- 事件处理程序/事件侦听器
- OCM考试实验-Skillset1----Undo & Shared Server
- SpringMVC之组合注解@GetMapping
- C++线程安全的单例模式
- 出现 java.net.UnknowHostException: XXX.XXX.XXX 异常的原因及解决方法