2016-11-23 72 views
1

我有问题,我想制作一个标题菜单,如平板电脑或手机中的菜单。它看起来像这样,但我们只看到7 Button和8 Button在Stackpanel的查看区域之外。WPF scrollviewer滚动没有滚动条可见像触摸,但与鼠标

当我在StackPanel中单击我能够通过左右键水平滚动,但我想,按我的mousebutton时,即ICH还可以通过它滚动:d

我不发现enything这样的,所以我希望你能帮助我: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> 
+0

它应该工作,因为你没有垂直滚动鼠标滚轮应该自动指向水平滚动。我最好的选择是处理鼠标滚轮事件并手动处理。如果你想我可以解释更多 – Emad

回答

0

问题都有人准备好被张贴在堆栈, 你可以在这里找到它,有一个解决方案,

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

只是一个初步的解决方案,如果你切换MOUSEBUTTONDOWN和向上事件鼠标右键,然后ü可以拖动滚动用右键并按左键。我会继续寻找如何处理只剩下

+0

这个作品差不多。现在我不能滑动一切,但我不能按任何按钮,因为MouseLeftButtonDown事件用于Scroll事件或? – PCode

+0

@PCode。 ooooh ....嗯,这很有趣,发布你有新的代码,我可以尝试看看我能否找到解决方案,因为你的第一个问题已经得到解答,请将我的答案标记为正确:) – JohnChris

+0

@PCode,you可能会更好地发布一个新的问题发现新的问题,因为它是一个不同的问题,人们会有兴趣试图解决它 – JohnChris

相关问题