2010-12-09 4 views
0

내 wpf 양식에 이미지 및 토글 버튼 컨트롤이 있습니다. 이미지 위에 마우스를 놓고 토글 버튼에 이벤트를 발생시키고 싶습니다.이 이벤트는 토러스 버튼으로 들어가는 마우스를 시뮬레이트합니다.이미지 마우스에 발생 이벤트가 발생합니다.

어떤 이유인지 raiseEvent에서 충돌이 발생합니다.

코드 :

<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" Stretch="Fill" MouseEnter="imgMouseEnter_Event" /> 


</Grid> 

코드가 어떤 도움에 대한 이벤트 통해

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

감사합니다.

+0

그것은 예외 세부 정보를 표시합니까? 그들을 게시하십시오. – decyclone

+0

아니요 - 빠른 충돌 ... 모든 디버그 예외 처리가 검사됩니다. – Yanshof

+0

좋아, 이제는 일부 exection있어 'System.Windows.RoutedEventArgs'형식의 개체는 'System.Windows.Input.MouseEventArgs'형식으로 변환 할 수 없습니다. – Yanshof

답변

1

노력이

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

    } 
충돌 할 때
관련 문제