在WPF中绑定列表框项IsEnabled [英] Binding listbox item IsEnabled in WPF
本文介绍了在WPF中绑定列表框项IsEnabled的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经为此工作了大约一个小时.
我的问题很简单:
我有一个类似
的列表框
I''ve been working on this for about an hour.
My problem is very simple:
I''ve a listbox like
<listbox istabstop="True" keyboardnavigation.tabnavigation="Continue">
<listboxitem name="A" isenabled="{Binding EnableA}" content="aa"></listboxitem>
<listboxitem name="B" content="bb"></listboxitem>
</listbox>
我想在视图模型中使用EnableA切换IsEnabled属性..
在此先感谢您的帮助...
i want to switch the IsEnabled property using EnableA in the viewmodel..
thanks in advance for any help...
推荐答案
我认为您的问题出在您的表单构造函数中.您需要使用新语法实例化viewmodel.应该是这样的:-
I think your problem lies in your form constructor. you need to instantiate the viewmodel using the new syntax. It should be something like this:-
public testView(INavigationViewModel model, IEventAggregator eventaggricator)
{
InitializeComponent();
model viewModel = new model();
this.DataContext = viewModel;
this.eventaggricator = eventaggricator;
}
希望对您有帮助
Hope this helps
ListBox是Items容器.所以我通常在ViewModel中设置一个ObservableCollection of Models;每个模型的每个绑定属性都有INotifyPropertyChanged;然后将Listbox使用ItemTemplate绑定到ObservableCollection,以格式化每个Model的显示.
然后只需切换适当的Model的boolean属性,并且如果绑定正确,相应的ListBoxItem Enabled状态就会更改.
ListBox is an Items container. so I usually set up an ObservableCollection of Models in the ViewModel; each Model has INotifyPropertyChanged for each bound property; and the Listbox is bound to the ObservableCollection using an ItemTemplate to format the displaying of each Model.
Then it is just a matter of toggling the appropriate Model''s boolean property and the corresponding ListBoxItem Enabled state will change if correctly bound.
这篇关于在WPF中绑定列表框项IsEnabled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文