专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Silverlight

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

发布时间:2011-06-27 20:15:43 文章来源:www.iduyao.cn 采编人员:星星草
当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>
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: