Binding ICommand to WPT tabcontrol / tabitem using XAML (MVVM)

I have a WPF 3.5 application built using the MVVM pattern. I have a tabcontrol, and I want to outperform ICommand in the view model when the user clicks on a specific tab (in my case, the Preview tab). How to connect ICommand to tabitem or tabcontrol using only XAML? I use MVVM, so I don’t want to use events and get dirty, dirty code in the code.

I think I missed something simple here! Thanks P

+3
source share
2 answers

Please refer to this article: connecting commands to events

Or you can use this approach

+1

InvokeCommandAction, :

        <TabItem Header="TabItem">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseLeftButtonDown">
                    <i:InvokeCommandAction Command="SomeCommand"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <Grid />
        </TabItem>

xmlns :

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

, , System.Windows.Interactivity ( WPF4)

+1

Source: https://habr.com/ru/post/1795652/


All Articles