問題我有bubbeling事件的問題。我設法在邊界,網格,堆棧面板中將事件冒泡,但不是在ScrollViewer中。如果您查看下面的示例,您會注意到,當您單擊TextBlock時,事件將被標記爲網格。但是,當我包含ScrollViewer時,事件在此停止,並且不會發送到網格。與事件bubbeling(ScrollViewer中)
有誰現在whay這happends,如果它可以解決嗎?當我一直使用ScrollViewer時,我確實需要能夠通過ScrollViewer將事件進行冒泡。
<Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown">
<!--<ScrollViewer MouseLeftButtonDown="ScrollViewer_MouseLeftButtonDown">-->
<StackPanel Orientation="Vertical" MouseLeftButtonDown="StackPanel_MouseLeftButtonDown">
<TextBlock Text="Click me to bubble an event" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown"/>
</StackPanel>
<!--</ScrollViewer>-->
</Grid>
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("LayoutRoot clicked");
}
private void ScrollViewer_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("ScrollViewer clicked");
e.Handled = false;
}
private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("StackPanel clicked");
e.Handled = false;
}
private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Textblock clicked");
e.Handled = false;
}
}
的ScrollViewer是一個密封類,不能從使用的AddHandler的。 – Adam 2013-07-29 20:44:52