1

I have the following xaml code:

<Window.Triggers>
    <EventTrigger RoutedEvent="MouseEnter">
        <EventTrigger.Actions>
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.5" Storyboard.TargetName="BackgroundBrush" From="0.5">
                    </DoubleAnimation>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger.Actions>
    </EventTrigger>

Also, I want to call some function when MouseEnter is raised

    void UpdateTimeAfterMouseOver()
    {
        timeAfterLastMouseOver = _timeAfterLastMouseOver_init;
    }

how to do it? I imaging it to do via command model, but can't imaging how :)

Oleg Sh
  • 8,496
  • 17
  • 89
  • 159
  • 1
    yes, it's better to use event hanlder. if you indeed want to call method from xaml. you may find a solution from here http://stackoverflow.com/questions/3041718/function-call-within-xaml-code – Terry Ma May 01 '13 at 11:49
  • 1
    I assume you are using MVVM. Just because you are using MVVM, you do not have to avoid all code-behind. Code-behind which controls/manipulates the View without reading the Data or writing to it is just fine in your code-behind, so you can use a EventHandler. – Florian Gl May 01 '13 at 13:09
  • Does this answer your question? [How do I call a call method from XAML in WPF?](https://stackoverflow.com/questions/2186382/how-do-i-call-a-call-method-from-xaml-in-wpf) – StayOnTarget May 08 '20 at 14:44

1 Answers1

2

I would simply use MouseEnter Event.

<Window MouseEnter="OnMouseEnterHandler"

.

void OnMouseEnterHandler(object sender, MouseEventArgs e)
{
    ...
}
LPL
  • 16,827
  • 6
  • 51
  • 95