2

i have the problem that i want to make a header Menu like a Menu in a Tablet or Mobilephone. It will look like this but we only see 7 Button and the 8 Button is outside of the viewing area in the Stackpanel.

When i click in the Stackpanel i am able to horizontally scroll by the left and right Keys, but i want that when my mousebutton is pressed, that ich can also scroll through it :D

i don't find enything like this, so i hope that you can help me :D

thanks

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>
2
  • It should work since you don't have vertical scroll mouse wheel should automatically point to horizontal scrolling. My best bet is to handle mouse wheel event and handle it manually. If you want I can explain more Commented Nov 23, 2016 at 9:45
  • Does this answer your question? in WPF. How to scroll Objects in ScrollViewer by mouse-dragging, like as iPhone? Commented Jul 14, 2020 at 15:42

1 Answer 1

2

Question has already been posted on stack, You can find it here, with a solution,

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

Just a preliminary solution, If you switch the MousebuttonDown and Up events to the Right mouse button, then u can drag scroll with right button and press with left. I'll keep looking how to do with just left

Sign up to request clarification or add additional context in comments.

5 Comments

This works almost. Now i can't slide everything but i can't press any Button in it because of the MouseLeftButtonDown event is used for the Scroll event or?
@PCode. ooooh.... hmm that is interesting, post the new code you have and I can try and see if I can find a solution, since your initial question has been answered, please mark my answer as correct:)
@PCode, you are probably better off posting a new question for the new problem found, as its a different question, people would be interested in trying to solve it
Ok Sorry, i am new here 😊 the Answer of JohnChris was correct and solved my first peoblem.
@PCcode, haha thank you, but there is a vote system, where people get points when they help, u see next to the top, there is a 0 and two arrows and a tick underneath? If you click the up arrow it vote the answer is good, if you vote down, it votes the answer was bad, if you click the tick, it means the answer fixed your problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.