2016-11-23 70 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

相關問題