none
wpf 点击scrollviewer内部控件会使scrollviewer滚动 RRS feed

  • 问题

  • 如上图所示,点击scrollviewer内部的控件时会使scrollviewer跟随着移动,如何去掉这个跟随显示。

    2014年4月4日 5:35

答案

  • 你好,

    你只需要处理ScrollViewer中容器控件的RequestBringIntoView事件,设置为已经处理即可,例如:

    <ScrollViewer x:Name="_mainVScrollViewer">
                <StackPanel Width="500" RequestBringIntoView="OnRequestBringIntoView">
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                    <Button Content="Button" Margin="16,16,16,16" Height="150" Width="500"/>
                </StackPanel>
            </ScrollViewer>

    后台:

    void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
    {
                e.Handled = true;
    }

    这样,即使点击下面的按钮,也不会自动滚动:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 skczjun 2014年4月8日 0:52
    2014年4月7日 1:50
    版主