没有滚动条的WPF滚动查看器滚动,如Touch,但有鼠标

时间:2016-11-23 09:00:22

标签: c# wpf xaml

我有一个问题,我想在平板电脑或手机中制作标题菜单,如菜单。它看起来像这样,但我们只看到7个按钮,8个按钮位于Stackpanel的查看区域之外。

当我在Stackpanel中单击时,我可以通过左右键水平滚动,但我希望当按下我的鼠标按钮时,也可以滚动它:D

我没有找到这样的东西,所以我希望你能帮助我:D

感谢

enter image description here

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="200"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="110"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="100"/>
    </Grid.RowDefinitions>
    <Rectangle Name="rectangel1" Grid.RowSpan="3">
        <Rectangle.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF0036A0" Offset="0.003"/>
                <GradientStop Color="#FFE9EDFF" Offset="1"/>
            </LinearGradientBrush>
        </Rectangle.Fill>
    </Rectangle>
    <Grid Grid.Column="1" Grid.ColumnSpan="2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="750"/>
            <ColumnDefinition Width="20"/>
        </Grid.ColumnDefinitions>
        <ScrollViewer Name="scrollviewer1" Grid.Column="1" Grid.ColumnSpan="2" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled">

            <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.ColumnSpan="1">
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn1" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Button 1" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn2" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Button 2" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn3" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Button 3" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn4" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Button 4" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn5" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Button 5" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn6" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Button 6" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,10,10">
                    <Rectangle Name="btn7" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Button 7" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
                <Grid Width="87" Height="90" Margin="10,10,50,10">
                    <Rectangle Name="btn8" Fill="#FFF39999" RadiusX="10" RadiusY="10" />
                    <Label Content="Button 8" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="16" FontWeight="Bold"/>
                </Grid>
            </StackPanel>

    </ScrollViewer>

    <Rectangle Name="rectlinks" Grid.Column="0" Fill="#FFFF7676" MouseEnter="rectlinks_MouseEnter" />
    <Rectangle Name="rectrechts" Grid.Column="2" MouseEnter="rectrechts_MouseEnter" Fill="#FFFF7474"  />
</Grid>

1 个答案:

答案 0 :(得分:0)

问题已在贴纸上发布, 你可以在这里找到解决方案,

in WPF. How to scroll Objects in ScrollViewer by mouse-dragging, like as iPhone?

只是一个初步的解决方案,如果你将MousebuttonDown和Up事件切换到鼠标右键,那么你可以用右键拖动滚动,然后按左键。我将继续关注左边的