我有我的XAML代碼:的Silverlight:如何防止路由從兒童帆布mouseMove事件其父帆布
<Canvas x:Name="mainCanvas" Width="200" Height="150" Background="LightGray"
MouseLeftButtonUp="mainCanvas_MouseLeftButtonUp"
MouseMove="mainCanvas_MouseMove">
<Canvas x:Name="topCanvas" Width="200" Height="100" Background="LightBlue"
MouseLeftButtonUp="topCanvas_MouseLeftButtonUp"
MouseMove="topCanvas_MouseMove">
</Canvas>
</Canvas>
及其後面的代碼:
private void topCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("topCanvas_MouseLeftButtonUp");
e.Handled = true; // This can prevent routing to the mainCanvas
}
private void mainCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("mainCanvas_MouseLeftButtonUp");
}
private void topCanvas_MouseMove(object sender, MouseEventArgs e)
{
Debug.WriteLine("topCanvas_MouseMove");
// How to prevent routing to the mainCanvas?
// e.Handled = true does NOT exist in MouseEventArgs
}
private void mainCanvas_MouseMove(object sender, MouseEventArgs e)
{
Debug.WriteLine("mainCanvas_MouseMove");
}
我的問題已經在評論。
如何防止將MouseMove事件從topCanvas(子畫布)路由到mainCanvas(父畫布)?
謝謝。
Peter
我不明白你的問題。如果您不想將該事件從您的xaml – MyKuLLSKI 2012-01-16 06:16:42
中移除,請將其移除。有時我需要它,有時我不需要它。上面的代碼只是一個例子。 – 2012-01-16 06:37:49
你知道什麼時候需要它,什麼時候不需要? – MyKuLLSKI 2012-01-16 14:05:47