mattsven
mattsven

Reputation: 23303

Set Grid's IsMouseOver to True in C#

I have a style with a Trigger for IsMouseOver, and I want to trigger that Trigger (heh) from C#. How can this be done? Thanks in advance!

Upvotes: 2

Views: 489

Answers (1)

Kirk Broadhurst
Kirk Broadhurst

Reputation: 28738

You can create a DataTrigger and then bind to a property in your ViewModel.

First create a bool property that will advise the View whether it should 'show' or 'not show' your style.

public bool GridTrigger
{
    get { return this.gridTrigger; }
    set { // raise a PropertyChange event, as per normal
}

And then add the DataTrigger to the XAML

<Grid.Triggers>
    <DataTrigger Binding="{Binding GridTrigger}" Value="True">
        <Setter Property="Style" Value="{StaticResource MyMouseOverStyle"/>
    </DataTrigger>
</Grid.Triggers>

This obviously assumes you are using MVVM!

Upvotes: 2

Related Questions