2017-04-07 32 views
0

button의 contentcontrol 태그 내에 두 개의 textblock 요소가있는 간단한 버튼이 있습니다. 문제는 텍스트 블록 컨트롤의 mouseup 이벤트가 호출되지 않는다는 것입니다. 대신 button의 onclick even1t는 textblock 컨트롤을 클릭 할 때마다 호출됩니다. 나는 <Button> 태그 외부 ContentControl을 태그를 배치하면버튼의 contentcontrol 내에서 WPF 텍스트 블록 이벤트가 호출되지 않습니다.

<Button> 
<ContentControl> 
<Textblock x:name="txt1" Text="Tes1-1" MouseLeftButtonUp="txt1_mouseleftbuttonup"/> 

<Textblock x:name="txt2" Text="Tes1-1" MouseLeftButtonUp="txt2_mouseleftbuttonup"/> 

<ContentControl> 

</button> 

후 이벤트 그러나 작동합니다.

+0

+0

보인다. 그냥 button_Click 이벤트 처리기에서 e.Handled = false로 설정하려고합니다. –

+0

tx lukas koten .. 나는 시도했지만 작동하지 않았다 ... 심지어 메시지 수신 파이프에서 더 높은 위치에 배치 할 수 있다고 생각하는 텍스트 블록에 Z- 인덱스 속성을 설정하려고 시도했지만 이벤트를 트리거 할 수도 있지만 너무 다른 제안이 있습니까? –

답변

-1

이벤트 아래 MouseLeftButton 핸들 : 그것은 당신이 당신의 TextBlocks을 위해하는 MouseLeftButtonUp 이벤트 핸들러를 시작할 수있는 방법은 아니지만, 당신이하는 MouseLeftButtonUp 이벤트를 당신의 TextBlocks에 처리 할 수있는 방법을 방법입니다

<Button Click="Button_Click_1"> 
    <ContentControl> 
     <TextBlock x:Name="txt11" Text="test" MouseLeftButtonDown="txt1_mouseleftButtonup"/> 
    </ContentControl> 
</Button> 
+1

왜 downvote ...? 코드를 사용해보십시오 :) 위의 설명에서 제안 된대로 button_Click에서 Handled 속성을 false로 설정하면 전혀 이해가되지 않습니다. – mm8

0

:

<Button Mouse.PreviewMouseUp="Button_MouseLeftButtonUp"> 
    <ContentControl> 
     <TextBlock Text="TestText" x:Name="txt1"/> 
    </ContentControl> 
</Button> 

private void Button_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
{ 
    var btn = sender as Button; if (btn == null) return; 

    if (btn.InputHitTest(e.GetPosition(btn)) is TextBlock) 
    { 
     ;//TextBlock MouseUp handler 
    } 
} 
+0

Yessss ... 감사의 톤 Rekshino :-). ... 그 일을 했어 ... 오늘 새로운 일을 배웠다 –

+0

그러면 답을 받아 들일 수있다. ;) – Rekshino