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);
}
精彩评论