我有問題,我想製作一個標題菜單,如平板電腦或手機中的菜單。它看起來像這樣,但我們只看到7 Button和8 Button在Stackpanel的查看區域之外。WPF scrollviewer滾動沒有滾動條可見像觸摸,但與鼠標
當我在StackPanel中單擊我能夠通過左右鍵水平滾動,但我想,按我的mousebutton時,即ICH還可以通過它滾動:d
我不發現enything這樣的,所以我希望你能幫助我: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>
它應該工作,因爲你沒有垂直滾動鼠標滾輪應該自動指向水平滾動。我最好的選擇是處理鼠標滾輪事件並手動處理。如果你想我可以解釋更多 – Emad