Xamarin forms vertical slider

hossein tavakoli 471 Reputation points
2021-06-18T08:41:33.297+00:00

I want a vertical slider placed left of screen.
I use this code :

<Grid x:Name="grdCameraViewer" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

                <Slider x:Name="sldCameraZoomValue" Maximum="50.0" Minimum="10.0"
                        VerticalOptions="Center" HorizontalOptions="FillAndExpand" Margin="0" Rotation="-90" />

</Grid>

it work for vertical slider, but I cannot put it left of screen.it placed center of screen.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
{count} votes

2 answers

Sort by: Most helpful
  1. PRASANT MOHANTY 1 Reputation point
    2021-06-18T09:10:24.357+00:00
    1. Use VerticalOptions="Left".
    0 comments No comments

  2. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-06-18T09:56:29.343+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    Just change the HorizontalOptions of your Grid to Start:

    <ContentPage.Content>  
        <Grid x:Name="grdCameraViewer" HorizontalOptions="Start" VerticalOptions="FillAndExpand">  
    
            <Slider x:Name="sldCameraZoomValue" Maximum="50.0" Minimum="10.0"  
                         VerticalOptions="Center" HorizontalOptions="FillAndExpand" Margin="0" Rotation="-90" />  
    
        </Grid>  
    </ContentPage.Content>  
    

    Note: At this time ,we will find the slider is very small .
    107018-image.png

    As a test, when I increased the width and height as follows:

    <Grid x:Name="grdCameraViewer" HorizontalOptions="Start" VerticalOptions="FillAndExpand" BackgroundColor="Gray">  
        <Slider x:Name="sldCameraZoomValue" Maximum="50.0" Minimum="10.0" WidthRequest="300" HeightRequest="50" BackgroundColor="Yellow"  
                      VerticalOptions="Center" HorizontalOptions="FillAndExpand" Margin="0" Rotation="-90" />  
    </Grid>  
    

    The result is:

    107017-image.png

    We will find that as the width and height of the slider increases, so does the distance to the left of the slider.
    This means that when the horizontal slider is adjusted to be vertical, the slider still occupies the corresponding width in the horizontal direction.

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.