文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>以ViewModel的方式绑定itemselect

以ViewModel的方式绑定itemselect

时间:2011-04-19  来源:fannet

public class ViewModel : INotifyPropertyChanged
{
private Item _selectedItem;
public ViewModel()
{
Items
= new ObservableCollection<Item>()
{
new Item {Name = "Foo"},
new Item {Name = "Bar"}
};
foreach ( Item anItem in Items
{
anItem.PropertyChanged
+= OnItemIsSelectedChanged;
}
}
public ObservableCollection<Item> Items { get; private set; }
public Item SelectedItem
{
get { return _selectedItem; }
set { // only update if the value is difference, don't
// want to send false positives
if ( _selectedItem == value )
{
return;
}

_selectedItem
= value;
OnPropertyChanged(
"SelectedItem");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnItemIsSelectedChanged(object sender, PropertyChangedEventArgs e)
{
if ( e.PropertyName != "IsSelected" )
{
return;
}
SelectedItem
= sender as Item;
}
private void OnPropertyChanged(string propertyName)
{
if ( PropertyChanged != null )
{
PropertyChanged(
this, new PropertyChangedEventArgs(propertyName));
}
}
}

from:http://stackoverflow.com/questions/985868/mvvm-binding-to-list-isselected-while-tracking-issynchronizedwithcurrentitem

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载