Question

I have a TabControl with a few TabItems. I want one of my TabItems to act as a button. When I click on the TabItem, I want it to execute a Command in my associated ViewModel. I have the following code in my View:

         <TabItem  Header="Manage Users" Visibility="{Binding IsAdmin, Converter={StaticResource VisibilityOfBool}}" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseLeftButtonDown">
                    <i:InvokeCommandAction Command="{Binding Path=OpenLoginCommand}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TabItem>

The OpenLoginCommand is an ICommand in the ViewModel. I have the interactivity namespace defined. What am I missing here?

Was it helpful?

Solution

Try PreviewMouseLeftButtonDown

<TabItem  Header="Manage Users" Visibility="{Binding IsAdmin, Converter={StaticResource VisibilityOfBool}}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="PreviewMouseLeftButtonDown">
            <i:InvokeCommandAction Command="{Binding Path=OpenLoginCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TabItem>

OTHER TIPS

Try using MouseDown instead of MouseLeftButtonDown as referencing MSDN the latter event doesn't exist on a TabItem control.

If your requirements insist on left-button only, then check the state of the mouse within the command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top