我想在选择 TabControl 的 TabItem 时调用命令。
有没有办法在不破坏 MVVM 模式的情况下做到这一点?
Use an 附加命令行为 http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/,这将让您将命令绑定到 WPF 事件
<TabControl ...
local:CommandBehavior.Event="SelectionChanged"
local:CommandBehavior.Command="{Binding TabChangedCommand}" />
当然,如果你使用MVVM设计模式和绑定SelectedItem
or SelectedIndex
,您还可以在PropertyChanged
event
void MyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "SelectedIndex")
RunTabChangedLogic();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)