如何抑制孩子调用父母的事件?

时间:2014-08-11 08:02:46

标签: c# wpf events user-controls awesomium

我正在创建简单的基于触摸的用户comtol Web浏览器。我使用ManipulationDelta事件进行平移,放大,缩小等操作。浏览器(Awesomium WebControl)位于控件网格内。当我尝试滚动页面整个浏览器移动。怎么压抑childen调用父母的事件? 我已将用户输入类型设置为ViewInput.Mouse,因为我想自己处理触摸。

XAML:

<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:awe="http://schemas.awesomium.com/winfx" x:Name="_control" x:Class="WebControlTouch.WebBrowser" 
             mc:Ignorable="d" d:DesignWidth="497" Height="323.333">
    <Grid TouchDown="_mainGrid_TouchDown" x:Name="_mainGrid" Background="Honeydew" Grid.Row="0" Margin="0,0,-66,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="8*"/>
            <ColumnDefinition Width="466*"/>
            <ColumnDefinition Width="8*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="84*"/>
            <RowDefinition Height="7*"/>
            <RowDefinition Height="220*"/>
            <RowDefinition Height="12*"/>
        </Grid.RowDefinitions>
        <awe:WebControl TouchDown="_browser_TouchDown"  Visibility="Visible" LoadingFrameFailed="_browser_LoadingFrameFailed" LoadingFrameComplete="_browser_LoadingFrameComplete" LoadingFrame="_browser_LoadingFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Name="_browser" AddressChanged="_browser_AddressChanged" Width="Auto" Height="Auto"  Grid.Row="2" Grid.Column="1" Margin="0,0,1,0"/>
        <TextBox Grid.Row="0" HorizontalAlignment="Left" Name="_addressBar" Height="43" Margin="0,10,0,0" TextWrapping="Wrap" Text="Address" VerticalAlignment="Top" Width="146" Grid.ColumnSpan="2"/>
        <Button x:Name="_goButton" Grid.Row="0" TouchDown="Button_TouchDown" Content="Go!" HorizontalAlignment="Left" Margin="131,10,0,0" VerticalAlignment="Top" Width="132" RenderTransformOrigin="-0.164,0.514" Height="43" Click="Button_Click" Grid.Column="1"/>
        <Button TouchDown="Btn_back" x:Name="_btnBack" Content="Back" Click="Btn_back" HorizontalAlignment="Left" Margin="276,10,0,0" VerticalAlignment="Top" Width="75" Grid.Column="1" Height="20"/>
        <Button TouchDown="_btn_forward" x:Name="_btnForward" Content="Forward" HorizontalAlignment="Left" Margin="365,10,0,0" VerticalAlignment="Top" Width="75" Click="_btn_forward" Grid.Column="1" Height="20"/>
        <Label x:Name="_Status" Content="Ready" Margin="277,42,130,16" VerticalAlignment="Center" Grid.Column="1" Height="26"/>
        <Button x:Name="_exitButton" Content="Exit!" Grid.Column="1" HorizontalAlignment="Left" Margin="365,45,0,0" VerticalAlignment="Top" Width="75" TouchDown="_exitButton_TouchDown"/>
        <Button x:Name="_temp" Content="Scroll" Grid.Column="1" HorizontalAlignment="Left" Margin="459.312,10.04,0,0" VerticalAlignment="Top" Width="75" Click="_tempClick"/>

    </Grid>
</UserControl>

1 个答案:

答案 0 :(得分:1)

这意味着您希望某些事件停止冒泡(向上)控制层次结构。 您通常需要做的就是将事件标记为已处理(事件处理程序中的事件实例):

e.Handled = true;

在你的情况下应该是这样的:

private void _browser_TouchDown(object sender, TouchEventArgs e)
{ 
    //...
    e.Handled = true;
    //...
}