Bind a ICommand to a WPF tabcontrol/tabitem using XAML (MVVM)
I have a WPF 3.5 app built using MVVM pattern. I have a tabcontrol and I want to excecute an ICommand on the view model when the user clicks a certain tab (jn my case the "Preview" tab). How do I hook up my ICommand to the tabitem or tabcontrol using just the XAML? I am using M开发者_Go百科VVM so I dont want to use events and get filthy, dirty code in the code-behind.
I think Im missing something simple here! Thanks,P
Please refer this article : hooking up commands to events
Or you can use this approach
You should use InvokeCommandAction, Looks like this:
<TabItem Header="TabItem">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="SomeCommand"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid />
</TabItem>
Be sure to include the xmlns in the top:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
and of course to reference System.Windows.Interactivity
(new in WPF4)
精彩评论