goul
goul

Reputation: 853

Set VM property based on a mouse over event in the Xaml

I would like to set the value of a property in my VM to true once the MouseOver event on a DockPanel is raised. So far no luck with the triggers. Would you have any clue? Thanks

<DockPanel.Style>
    <Style>
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=MyProperty}" Value="True">
                <Setter Property="??" Value="??"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DockPanel.Style>

Upvotes: 0

Views: 691

Answers (2)

Mashton
Mashton

Reputation: 6415

I use the Interactivity namespace xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" to do things like this ...

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseEnter">
        <i:InvokeCommandAction Command="{Binding DoSomethingCommand, Mode=OneWay}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

So now you have triggered a command in the VM based on an event in the view. Obviously the datacontext at this point must be the VM so that DoSomethingCommand can be triggered on the VM, but if not then just change it bubble out to a place where the data context is the VM ...

e.g.

Command=(Binding DataContext.DoSomethingCommand , RelativeSource={RelativeSource AncestorType=sdk:DataGrid}}

or whatever kind of element has your VM context.

Upvotes: 2

Daniel
Daniel

Reputation: 3364

I think if you assign datacontext to your whole page it would be picked by style as well. set something like a class and set property as it's value.

  property = {Binding YourDataContext.YournewValue}

Upvotes: 0

Related Questions