首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

当Canvas的父元素是ScrollViewer时调用FindElementsInHostCoordinates函数始终无法获得被命中的元素?该如何处理

2012-02-10 
当Canvas的父元素是ScrollViewer时调用FindElementsInHostCoordinates函数始终无法获得被命中的元素?当Can

当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);注册鼠标事件参考:

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> 

热点排行