簡體   English   中英

沒有滾動條的WPF滾動查看器滾動,如Touch,但有鼠標

[英]WPF scrollviewer scroll without scrollbar visible like Touch but with mouse

我有一個問題,我想在平板電腦或手機中制作標題菜單,如菜單。 它看起來像這樣,但我們只看到7個按鈕,8個按鈕位於Stackpanel的查看區域之外。

當我在Stackpanel中單擊時,我可以通過左右鍵水平滾動,但我希望當按下我的鼠標按鈕時,也可以滾動它:D

我沒有找到這樣的東西,所以我希望你能幫助我:D

謝謝

在此輸入圖像描述

<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>

問題已經在堆棧上發布了,您可以在這里找到解決方案,

在WPF中。 如何通過鼠標拖動滾動ScrollViewer中的對象,就像iPhone一樣?

只是一個初步的解決方案,如果你將MousebuttonDown和Up事件切換到鼠標右鍵,那么你可以用右鍵拖動滾動,然后按左鍵。 我會繼續看左邊怎么做

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM