开发者

Cant raise event on image mouse enter

开发者 https://www.devze.com 2023-01-29 10:03 出处:网络
On my wpf form i have image and toggle button controls. On image mouse over i want to raise event to the toggle button - this event will actully will simulate the mouser enter to the toggle button.

On my wpf form i have image and toggle button controls. On image mouse over i want to raise event to the toggle button - this event will actully will simulate the mouser enter to the toggle button.

For some reason i get crash on the raiseEvent.

The code:

<Grid>

    <Grid.RowDefinitions>
        <RowDefinition Height=".9*"/>
        <RowDefinition Height=".1*"/>
    </Grid.RowDefinitions>

    <ToggleButton Name="toggleBtn"  Grid.Row="0" Grid.RowSpan="2" Content="...test..." VerticalContentAlignment="Bottom" />

    <Image Name="imgCtrl" Grid.Row="0" Source="someImg.jpg" Stre开发者_运维百科tch="Fill" MouseEnter="imgMouseEnter_Event" />


</Grid>

The code that thru the event

    private void imgMouseEnter_Event( object sender, MouseEventArgs e )
    {
        toggleBtn.RaiseEvent( new RoutedEventArgs( ToggleButton.MouseEnterEvent ) );
    }

Thanks for any help.


try this

private void imgMouseEnter_Event(object sender, MouseEventArgs e)
    {
        MouseEventArgs mouse = new MouseEventArgs(Mouse.PrimaryDevice, 0);
        mouse.RoutedEvent = Mouse.MouseEnterEvent;
        toggleBtn.RaiseEvent(mouse);

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号