-2

I am working in wpf. I have a problem for triggering mouse over.

I have two buttons Button A and Button B. I need to trigger the Button B's MouseOver while i entered the mouse on Button B.

The solution is either C# or XAML.

I didnt have any idea about this problem. How to do this?

Karthik
  • 31
  • 1
  • 1
  • 7
  • 2
    See https://stackoverflow.com/questions/2907667/any-way-to-simulate-mouseover-in-wpf – Andy May 16 '19 at 10:32

1 Answers1

0

All UIElement has RaiseEvent() method. In that method, you can pass the object of MouseEventArgs.

XAML:

            <StackPanel Orientation="Vertical">
                <Button Name="buttonA" Click="buttonA_Click" Content="ButtonA" Height="25" Width="80" 
                MouseEnter="buttonA_MouseEnter" Margin="10 5 2 2" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                <Button Name="buttonB" Click="buttonB_Click" MouseEnter="buttonB_MouseEnter" Content="ButtonB" Height="25" Width="80" Margin="10 5 2 2"
                VerticalAlignment="Center" HorizontalAlignment="Left"/>
            </StackPanel>

xaml.cs:

            private void buttonA_MouseEnter(object sender, MouseEventArgs e)
            {
                MessageBox.Show("Message from Button A...! ");
            }

            private void buttonB_MouseEnter(object sender, MouseEventArgs e)
            {
                MouseEventArgs mouseEventArgs = new MouseEventArgs(Mouse.PrimaryDevice, 0);
                mouseEventArgs.RoutedEvent = Mouse.MouseEnterEvent;
                buttonA.RaiseEvent(mouseEventArgs);
            }
Muthukumar K
  • 311
  • 1
  • 9