[WPF] 컨트롤을 마우스 클릭/터치했을 때의 이벤트 흐름을 한번 확인②
⇒ h tps:// 퀵했다. 작은 m / 절 1707 / MS / 4f입니다 73D86 그림 d283 그림 C4f
이벤트 관련 복권
⇒ h tps:// 퀵했다. 작은 m/사 1707/있어 MS/4f다 73D86 그림에서 d283 그림 C4f#%그림 3%82%아 %96%아2%그림9%80%아3wpfaml
하고 싶은 일
문득 신경이 쓰여서 실험하고 싶어졌다.
화면의 외형상은 같은 아래와 같은 것에서도,
(빨간 그리드 위에 Button이있는 것처럼 보입니다)
이런 코드와,
1.xaml<Grid Background="Red">
<Button/>
</Grid>
이런 코드에서는
2.xaml<Grid Background="Red"/>
<Button/>
이벤트를 전하는 방법은 다른가요? 다시 확인하고 싶다.
사용하는 코드
이전에 쓴, 여기 을 베이스로 해, 일부, 이하와 같이 고친다.
Button이 Grid 밖에 있는 패턴(부모와 자식 관계 없음)
Button이 Grid 밖에있는 패턴 .xaml<Grid x:Name="MainGrid"
Background="#66FF0000"
Margin="50"
IsManipulationEnabled="True"
ManipulationStarting="MainGrid_ManipulationStarting"
ManipulationDelta="MainGrid_ManipulationDelta"
ManipulationCompleted="MainGrid_ManipulationCompleted"
PreviewMouseDown= "MainGrid_PreviewMouseDown" MouseDown="MainGrid_MouseDown"
PreviewMouseUp= "MainGrid_PreviewMouseUp" MouseUp="MainGrid_MouseUp"
PreviewTouchDown= "MainGrid_PreviewTouchDown" TouchDown="MainGrid_TouchDown"
PreviewTouchUp= "MainGrid_PreviewTouchUp" TouchUp="MainGrid_TouchUp"
PreviewStylusDown= "MainGrid_PreviewStylusDown" StylusDown="MainGrid_StylusDown"
PreviewStylusUp= "MainGrid_PreviewStylusUp" StylusUp="MainGrid_StylusUp"
PreviewMouseLeftButtonDown= "MainGrid_PreviewMouseLeftButtonDown" MouseLeftButtonDown="MainGrid_MouseLeftButtonDown"
PreviewMouseLeftButtonUp= "MainGrid_PreviewMouseLeftButtonUp" MouseLeftButtonUp="MainGrid_MouseLeftButtonUp"
PreviewMouseRightButtonDown= "MainGrid_PreviewMouseRightButtonDown" MouseRightButtonDown="MainGrid_MouseRightButtonDown"
PreviewMouseRightButtonUp= "MainGrid_PreviewMouseRightButtonUp" MouseRightButtonUp="MainGrid_MouseRightButtonUp">
</Grid>
<Button Margin="150" Content="ボタン"
Click="Button_Click"
PreviewMouseDown="Button_PreviewMouseDown" MouseDown="Button_MouseDown"
PreviewMouseUp="Button_PreviewMouseUp" MouseUp="Button_MouseUp"
PreviewTouchDown="Button_PreviewTouchDown" TouchDown="Button_TouchDown"
PreviewTouchUp="Button_PreviewTouchUp" TouchUp="Button_TouchUp"
PreviewStylusDown="Button_PreviewStylusDown" StylusDown="Button_StylusDown"
PreviewStylusUp="Button_PreviewStylusUp" StylusUp="Button_StylusUp"
PreviewMouseLeftButtonDown="Button_PreviewMouseLeftButtonDown" MouseLeftButtonDown="Button_MouseLeftButtonDown"
PreviewMouseLeftButtonUp="Button_PreviewMouseLeftButtonUp" MouseLeftButtonUp="Button_MouseLeftButtonUp"
PreviewMouseRightButtonDown="Button_PreviewMouseRightButtonDown" MouseRightButtonDown="Button_MouseRightButtonDown"
PreviewMouseRightButtonUp="Button_PreviewMouseRightButtonUp" MouseRightButtonUp="Button_MouseRightButtonUp"
/>
이 코드에서 버튼을 손가락으로 터치할 때 출력
Button_PreviewStylusDown
Button_StylusDown
Button_PreviewTouchDown
Button_TouchDown
Button_PreviewMouseLeftButtonDown
Button_PreviewMouseDown
Button_PreviewStylusUp
Button_StylusUp
Button_PreviewTouchUp
Button_TouchUp
Button_PreviewMouseLeftButtonUp
Button_PreviewMouseUp
Button_Click
버튼이 그리드에있는 패턴 (부모와 자식 관계 있음)
버튼이 그리드에있는 패턴 .xaml<Grid x:Name="MainGrid"
Background="#66FF0000"
Margin="50"
IsManipulationEnabled="False"
ManipulationStarting="MainGrid_ManipulationStarting"
ManipulationDelta="MainGrid_ManipulationDelta"
ManipulationCompleted="MainGrid_ManipulationCompleted"
PreviewMouseDown= "MainGrid_PreviewMouseDown" MouseDown="MainGrid_MouseDown"
PreviewMouseUp= "MainGrid_PreviewMouseUp" MouseUp="MainGrid_MouseUp"
PreviewTouchDown= "MainGrid_PreviewTouchDown" TouchDown="MainGrid_TouchDown"
PreviewTouchUp= "MainGrid_PreviewTouchUp" TouchUp="MainGrid_TouchUp"
PreviewStylusDown= "MainGrid_PreviewStylusDown" StylusDown="MainGrid_StylusDown"
PreviewStylusUp= "MainGrid_PreviewStylusUp" StylusUp="MainGrid_StylusUp"
PreviewMouseLeftButtonDown= "MainGrid_PreviewMouseLeftButtonDown" MouseLeftButtonDown="MainGrid_MouseLeftButtonDown"
PreviewMouseLeftButtonUp= "MainGrid_PreviewMouseLeftButtonUp" MouseLeftButtonUp="MainGrid_MouseLeftButtonUp"
PreviewMouseRightButtonDown= "MainGrid_PreviewMouseRightButtonDown" MouseRightButtonDown="MainGrid_MouseRightButtonDown"
PreviewMouseRightButtonUp= "MainGrid_PreviewMouseRightButtonUp" MouseRightButtonUp="MainGrid_MouseRightButtonUp">
<Button Margin="150" Content="ボタン"
Click="Button_Click"
PreviewMouseDown="Button_PreviewMouseDown" MouseDown="Button_MouseDown"
PreviewMouseUp="Button_PreviewMouseUp" MouseUp="Button_MouseUp"
PreviewTouchDown="Button_PreviewTouchDown" TouchDown="Button_TouchDown"
PreviewTouchUp="Button_PreviewTouchUp" TouchUp="Button_TouchUp"
PreviewStylusDown="Button_PreviewStylusDown" StylusDown="Button_StylusDown"
PreviewStylusUp="Button_PreviewStylusUp" StylusUp="Button_StylusUp"
PreviewMouseLeftButtonDown="Button_PreviewMouseLeftButtonDown" MouseLeftButtonDown="Button_MouseLeftButtonDown"
PreviewMouseLeftButtonUp="Button_PreviewMouseLeftButtonUp" MouseLeftButtonUp="Button_MouseLeftButtonUp"
PreviewMouseRightButtonDown="Button_PreviewMouseRightButtonDown" MouseRightButtonDown="Button_MouseRightButtonDown"
PreviewMouseRightButtonUp="Button_PreviewMouseRightButtonUp" MouseRightButtonUp="Button_MouseRightButtonUp"
/>
</Grid>
이 코드에서 버튼을 손가락으로 터치할 때 출력
MainGrid_PreviewStylusDown
Button_PreviewStylusDown
Button_StylusDown
MainGrid_StylusDown
MainGrid_PreviewTouchDown
Button_PreviewTouchDown
Button_TouchDown
MainGrid_TouchDown
MainGrid_PreviewMouseLeftButtonDown
MainGrid_PreviewMouseDown
Button_PreviewMouseLeftButtonDown
Button_PreviewMouseDown
MainGrid_PreviewStylusUp
Button_PreviewStylusUp
Button_StylusUp
MainGrid_StylusUp
MainGrid_PreviewTouchUp
Button_PreviewTouchUp
Button_TouchUp
MainGrid_TouchUp
MainGrid_PreviewMouseLeftButtonUp
MainGrid_PreviewMouseUp
Button_PreviewMouseLeftButtonUp
Button_PreviewMouseUp
Button_Click
결과
그리드 위에 버튼이있는 것처럼 보이는 화면에서도 그리드에 Button이 있고 (= Grid와 Button에 부모 - 자식 관계가 있음) 또는 Grid 외부에 Button이 있습니다 (= Grid와 Button에 부모 - 자식 관계가 없습니다. )에서 이벤트 전파 방식이 다르다.
■ 왼쪽이 부모와 자식 관계 없음, 오른쪽이 부모와 자식 관계 있음
당연할지도 모르지만, 결과적으로,
<Grid Background="Red">
<Button/>
</Grid>
<Grid Background="Red"/>
<Button/>
이전에 쓴, 여기 을 베이스로 해, 일부, 이하와 같이 고친다.
Button이 Grid 밖에 있는 패턴(부모와 자식 관계 없음)
Button이 Grid 밖에있는 패턴 .xaml
<Grid x:Name="MainGrid"
Background="#66FF0000"
Margin="50"
IsManipulationEnabled="True"
ManipulationStarting="MainGrid_ManipulationStarting"
ManipulationDelta="MainGrid_ManipulationDelta"
ManipulationCompleted="MainGrid_ManipulationCompleted"
PreviewMouseDown= "MainGrid_PreviewMouseDown" MouseDown="MainGrid_MouseDown"
PreviewMouseUp= "MainGrid_PreviewMouseUp" MouseUp="MainGrid_MouseUp"
PreviewTouchDown= "MainGrid_PreviewTouchDown" TouchDown="MainGrid_TouchDown"
PreviewTouchUp= "MainGrid_PreviewTouchUp" TouchUp="MainGrid_TouchUp"
PreviewStylusDown= "MainGrid_PreviewStylusDown" StylusDown="MainGrid_StylusDown"
PreviewStylusUp= "MainGrid_PreviewStylusUp" StylusUp="MainGrid_StylusUp"
PreviewMouseLeftButtonDown= "MainGrid_PreviewMouseLeftButtonDown" MouseLeftButtonDown="MainGrid_MouseLeftButtonDown"
PreviewMouseLeftButtonUp= "MainGrid_PreviewMouseLeftButtonUp" MouseLeftButtonUp="MainGrid_MouseLeftButtonUp"
PreviewMouseRightButtonDown= "MainGrid_PreviewMouseRightButtonDown" MouseRightButtonDown="MainGrid_MouseRightButtonDown"
PreviewMouseRightButtonUp= "MainGrid_PreviewMouseRightButtonUp" MouseRightButtonUp="MainGrid_MouseRightButtonUp">
</Grid>
<Button Margin="150" Content="ボタン"
Click="Button_Click"
PreviewMouseDown="Button_PreviewMouseDown" MouseDown="Button_MouseDown"
PreviewMouseUp="Button_PreviewMouseUp" MouseUp="Button_MouseUp"
PreviewTouchDown="Button_PreviewTouchDown" TouchDown="Button_TouchDown"
PreviewTouchUp="Button_PreviewTouchUp" TouchUp="Button_TouchUp"
PreviewStylusDown="Button_PreviewStylusDown" StylusDown="Button_StylusDown"
PreviewStylusUp="Button_PreviewStylusUp" StylusUp="Button_StylusUp"
PreviewMouseLeftButtonDown="Button_PreviewMouseLeftButtonDown" MouseLeftButtonDown="Button_MouseLeftButtonDown"
PreviewMouseLeftButtonUp="Button_PreviewMouseLeftButtonUp" MouseLeftButtonUp="Button_MouseLeftButtonUp"
PreviewMouseRightButtonDown="Button_PreviewMouseRightButtonDown" MouseRightButtonDown="Button_MouseRightButtonDown"
PreviewMouseRightButtonUp="Button_PreviewMouseRightButtonUp" MouseRightButtonUp="Button_MouseRightButtonUp"
/>
이 코드에서 버튼을 손가락으로 터치할 때 출력
Button_PreviewStylusDown
Button_StylusDown
Button_PreviewTouchDown
Button_TouchDown
Button_PreviewMouseLeftButtonDown
Button_PreviewMouseDown
Button_PreviewStylusUp
Button_StylusUp
Button_PreviewTouchUp
Button_TouchUp
Button_PreviewMouseLeftButtonUp
Button_PreviewMouseUp
Button_Click
버튼이 그리드에있는 패턴 (부모와 자식 관계 있음)
버튼이 그리드에있는 패턴 .xaml
<Grid x:Name="MainGrid"
Background="#66FF0000"
Margin="50"
IsManipulationEnabled="False"
ManipulationStarting="MainGrid_ManipulationStarting"
ManipulationDelta="MainGrid_ManipulationDelta"
ManipulationCompleted="MainGrid_ManipulationCompleted"
PreviewMouseDown= "MainGrid_PreviewMouseDown" MouseDown="MainGrid_MouseDown"
PreviewMouseUp= "MainGrid_PreviewMouseUp" MouseUp="MainGrid_MouseUp"
PreviewTouchDown= "MainGrid_PreviewTouchDown" TouchDown="MainGrid_TouchDown"
PreviewTouchUp= "MainGrid_PreviewTouchUp" TouchUp="MainGrid_TouchUp"
PreviewStylusDown= "MainGrid_PreviewStylusDown" StylusDown="MainGrid_StylusDown"
PreviewStylusUp= "MainGrid_PreviewStylusUp" StylusUp="MainGrid_StylusUp"
PreviewMouseLeftButtonDown= "MainGrid_PreviewMouseLeftButtonDown" MouseLeftButtonDown="MainGrid_MouseLeftButtonDown"
PreviewMouseLeftButtonUp= "MainGrid_PreviewMouseLeftButtonUp" MouseLeftButtonUp="MainGrid_MouseLeftButtonUp"
PreviewMouseRightButtonDown= "MainGrid_PreviewMouseRightButtonDown" MouseRightButtonDown="MainGrid_MouseRightButtonDown"
PreviewMouseRightButtonUp= "MainGrid_PreviewMouseRightButtonUp" MouseRightButtonUp="MainGrid_MouseRightButtonUp">
<Button Margin="150" Content="ボタン"
Click="Button_Click"
PreviewMouseDown="Button_PreviewMouseDown" MouseDown="Button_MouseDown"
PreviewMouseUp="Button_PreviewMouseUp" MouseUp="Button_MouseUp"
PreviewTouchDown="Button_PreviewTouchDown" TouchDown="Button_TouchDown"
PreviewTouchUp="Button_PreviewTouchUp" TouchUp="Button_TouchUp"
PreviewStylusDown="Button_PreviewStylusDown" StylusDown="Button_StylusDown"
PreviewStylusUp="Button_PreviewStylusUp" StylusUp="Button_StylusUp"
PreviewMouseLeftButtonDown="Button_PreviewMouseLeftButtonDown" MouseLeftButtonDown="Button_MouseLeftButtonDown"
PreviewMouseLeftButtonUp="Button_PreviewMouseLeftButtonUp" MouseLeftButtonUp="Button_MouseLeftButtonUp"
PreviewMouseRightButtonDown="Button_PreviewMouseRightButtonDown" MouseRightButtonDown="Button_MouseRightButtonDown"
PreviewMouseRightButtonUp="Button_PreviewMouseRightButtonUp" MouseRightButtonUp="Button_MouseRightButtonUp"
/>
</Grid>
이 코드에서 버튼을 손가락으로 터치할 때 출력
MainGrid_PreviewStylusDown
Button_PreviewStylusDown
Button_StylusDown
MainGrid_StylusDown
MainGrid_PreviewTouchDown
Button_PreviewTouchDown
Button_TouchDown
MainGrid_TouchDown
MainGrid_PreviewMouseLeftButtonDown
MainGrid_PreviewMouseDown
Button_PreviewMouseLeftButtonDown
Button_PreviewMouseDown
MainGrid_PreviewStylusUp
Button_PreviewStylusUp
Button_StylusUp
MainGrid_StylusUp
MainGrid_PreviewTouchUp
Button_PreviewTouchUp
Button_TouchUp
MainGrid_TouchUp
MainGrid_PreviewMouseLeftButtonUp
MainGrid_PreviewMouseUp
Button_PreviewMouseLeftButtonUp
Button_PreviewMouseUp
Button_Click
결과
그리드 위에 버튼이있는 것처럼 보이는 화면에서도 그리드에 Button이 있고 (= Grid와 Button에 부모 - 자식 관계가 있음) 또는 Grid 외부에 Button이 있습니다 (= Grid와 Button에 부모 - 자식 관계가 없습니다. )에서 이벤트 전파 방식이 다르다.
■ 왼쪽이 부모와 자식 관계 없음, 오른쪽이 부모와 자식 관계 있음
당연할지도 모르지만, 결과적으로,
トンネリング
, バブリング
의 원리로 이벤트가 전해진다. Reference
이 문제에 관하여([WPF] 컨트롤을 마우스 클릭/터치했을 때의 이벤트 흐름을 한번 확인②), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tera1707/items/9ddb9d67943cc6202c88텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)