我是靠谱客的博主 强健超短裙,最近开发中收集的这篇文章主要介绍mvvm绑定checkbox wpf_WPF的MVVM模式给ComboBox绑定数据和读取,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

在网上找到类似的代码:

XAML文件

对应的ViewModel文件

public classLocationRoad

{public int ID { set; get; }public string Code { set; get; }public string Info { set; get; }

}/当ComboBox选中项更改时发生///privateLocationRoad _selectLocation;publicLocationRoad SelectLocation

{get{return this._selectLocation;

}set{this._selectLocation =value;if (this.PropertyChanged != null)

PropertyChanged(this, new PropertyChangedEventArgs("SelectLocation"));

}

}private ObservableCollection _locationRoad = null;publicObservableCollection LocationSource

{get{if (this._locationRoad == null)

{this._locationRoad = newObservableCollection() {new LocationRoad() { ID = 1, Code = "NGQ", Info = "南岗区"},new LocationRoad() { ID = 2, Code = "DLQ", Info = "道里区"},new LocationRoad() { ID = 3, Code = "DWQ", Info = "道外区"},new LocationRoad() { ID = 4, Code = "PFQ", Info = "平房区"},new LocationRoad() { ID = 5, Code = "XFQ", Info = "香坊区"},

};

}return this._locationRoad;

}set{this._locationRoad =value;if (this.PropertyChanged != null)

PropertyChanged(this, new PropertyChangedEventArgs("LocationSource"));

}

}

如果要进行双向绑定或其他的绑定方式,只要更改上面binging块中的Mode方式就可以了。一般用不到吧?

============================================

我根据上面的代码,做了一点修改

SelectedItem="{Binding CbClientTypeSelectedItem}" MinWidth="70">

对应的ViewModel代码

publicCustomNodeItem _CbClientTypeSelectedItem;publicCustomNodeItem CbClientTypeSelectedItem

{get { return_CbClientTypeSelectedItem; }set{

_CbClientTypeSelectedItem=value;//if (SelectCallBack != null)//{//SelectCallBack(value);//}

NotifyOfPropertyChange();

}

}private List_CbClientType;public ListCbClientType

{get { return_CbClientType; }set{

_CbClientType=value;if (value != null && value.Count > 0 && CbClientTypeSelectedItem == null)

{

CbClientTypeSelectedItem=value.First();

}

NotifyOfPropertyChange();

}

}//在按钮的事件中获取选择项

public voidBtnTest()

{string msg =CbClientTypeSelectedItem.Descript;

MessageBox.Show(msg);

}

说明:这个应用在Caliburn.Micro中使用的

最后

以上就是强健超短裙为你收集整理的mvvm绑定checkbox wpf_WPF的MVVM模式给ComboBox绑定数据和读取的全部内容,希望文章能够帮你解决mvvm绑定checkbox wpf_WPF的MVVM模式给ComboBox绑定数据和读取所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部