当Canvas的父元素是ScrollViewer时调用FindElementsInHostCoordinates函数始终无法获得被命中的元素?该如何处理
当Canvas的父元素是ScrollViewer时调用FindElementsInHostCoordinates函数始终无法获得被命中的元素?
当Canvas的父元素是ScrollViewer时调用FindElementsInHostCoordinates函数始终无法获得被命中的元素,有什么解决办法?
详细见:http://kimiya25.spaces.live.com/blog/cns!27A083D4FD9435E9!2008.entry
------解决方案--------------------
这个问题的关建是ScrollView 需要通过scrollViewer.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Control_MouseDown), true);注册鼠标事件参考:
当Canvas的父元素是ScrollViewer时调用FindElementsInHostCoordinates函数始终无法获得被命中的元素,有什么解决办法?
详细见:http://kimiya25.spaces.live.com/blog/cns!27A083D4FD9435E9!2008.entry
------解决方案--------------------
这个问题的关建是ScrollView 需要通过scrollViewer.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Control_MouseDown), true);注册鼠标事件参考:
- XML code
<UserControl x:Class="LoadSilverlight.scrollViewMouseHitTest" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <Grid x:Name="LayoutRoot"> <Border x:Name="bdRootLayout"> <ScrollViewer x:Name="scrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Background="Yellow"> <Canvas x:Name="canvas" Background="#50FFFFFF"> <Rectangle Width="50" Height="50" Fill="Black" Stroke="Green" Canvas.Left="5" Canvas.Top="5" /> <Rectangle Width="50" Height="50" Fill="Black" Stroke="Green" Canvas.Left="55" Canvas.Top="5" /> <Rectangle Width="50" Height="50" Fill="Black" Stroke="Green" Canvas.Left="5" Canvas.Top="55" /> <Rectangle Width="50" Height="50" Fill="Black" Stroke="Green" Canvas.Left="55" Canvas.Top="55" /> </Canvas> </ScrollViewer> </Border> </Grid> </UserControl>