0

我正在设计一个 Windows Phone 应用程序。我在 a 中有一个Hyperlink对象RichTextBox,在 a 中Grid。有事件,Grid有事件。TapHyperlinkClick

单击Hyperlink也会引发父Grid级的 Tap 事件。我怎样才能防止这种情况?

我会e.HandledClick处理程序中使用,但RoutedEventArgs在 Silverlight for Windows Phone 中没有 Handled 属性...我还尝试遍历逻辑树以查找原始源,但单击似乎源自MS.Internal.RichTextBoxView控件(e.OriginalSource)...

4

1 回答 1

1

我认为Click处理程序本身没有任何好的方法。但是,以下状态管理可以工作:

XAML:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" Tap="ContentPanel_Tap_1">
    <RichTextBox Tap="RichTextBox_Tap_1">
       <Paragraph>
           fdsfdfdf
           <Hyperlink Click="Hyperlink_Click_1">fdsfdsfsaf</Hyperlink>
           fsdfsdfa
       </Paragraph>
   </RichTextBox>
</Grid>

和代码:

bool RtbTapHandled = false;

private void Hyperlink_Click_1(object sender, RoutedEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("Hyperlink");
    RtbTapHandled = true;
}

private void RichTextBox_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
    if (RtbTapHandled)
    {
        e.Handled = true;
    }

    RtbTapHandled = false;
    System.Diagnostics.Debug.WriteLine("RTB_Tap");
}

private void ContentPanel_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("Content_Tap");
}

在这种情况下,如果您单击 和 ,您将获得来自两者的RichTextBox回调,但如果您单击 ,您将获得虽然它会在该级别处理并停止。RichTextBox_Tap_1ContentPanel_Tap_1HyperlinkHyperlink_Click_1RichTextBox_Tap_1

于 2013-06-17T07:38:52.897 回答