• Silverlight 4 正确设置 ScrollViewer让它更好的支持鼠标滚轮


    先看一段Xaml代码:

    <Grid x:Name="LayoutRoot" Background="White">
        <ScrollViewer>
            <StackPanel Name="stackPanel1">
                <Button Content="Button 1" Width="150" />
                <Button Content="Button 2" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 3" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 4" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 5" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 6" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 7" Width="150" Margin="0,20,0,0" />
            </StackPanel>
        </ScrollViewer>
    </Grid>

    运行后会发现混动鼠标滚轮时,页面不能正常滚动,只有在“Button 1”等按钮文字上面,滚轮才生效。

    解决方法:

    增加ScrollViewer Background="Transparent"属性

    <Grid x:Name="LayoutRoot" Background="White">
        <ScrollViewer  Background="Transparent">
            <StackPanel Name="stackPanel1">
                <Button Content="Button 1" Width="150" />
                <Button Content="Button 2" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 3" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 4" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 5" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 6" Width="150" Margin="0,20,0,0" />
                <Button Content="Button 7" Width="150" Margin="0,20,0,0" />
            </StackPanel>
        </ScrollViewer>
    </Grid>

    鼠标在在ScrollViewer 元素内任意位置,滚动滚轮,一切正常!

    问题解决!

  • 相关阅读:
    使用Python学习RabbitMQ消息队列
    Python调用nmap扫描网段主机信息生成xml
    扫描网站服务器真实IP的小脚本
    C语言实现将彩色BMP位图转化为二值图
    Python socket编程之构造IP首部和ICMP首部
    ARP协议抓包之帧长度和Gratuitous ARP的问题
    合天解密200-找茬游戏
    合天misc100
    IDF实验室-简单的js解密
    IDF实验室—不难不易的js加密
  • 原文地址:https://www.cnblogs.com/starlet/p/2797043.html
Copyright © 2020-2023  润新知