0

I need some help with my ScollerViewer. Here is my code:

<UserControl x:Class="ConfigUI.Views.ProfileListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:local="clr-namespace:ConfigUI.Views"
             mc:Ignorable="d" 
             HorizontalAlignment="Center" VerticalAlignment="Top" 
             d:DesignHeight="700" d:DesignWidth="960">
    <Grid Margin="20" Height="500"
          ScrollViewer.CanContentScroll="True"
          ScrollViewer.VerticalScrollBarVisibility="Visible">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

       <Border ...
       /Border>

       <Border ...  /Border>

       <Border ... /Border>

   </Grid>
</UserControl>

What I want is to show a ScrollBar when this control shows and users can scroll to see the contents.

But now the scrollBar just won't show...

Anybody can help? Thanks.

2
  • @Clint, tried that. Still not working. Commented Feb 9, 2020 at 5:12
  • let me know if the answer below works Commented Feb 9, 2020 at 5:21

1 Answer 1

1

You cannot have ScrollViewer on Grid directly

Try this structure


<ScrollViewer VerticalScrollBarVisibility="Visible" CanContentScroll="True">
    <Grid Margin="20" Height="Auto">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

       <Border ...
       /Border>

       <Border ...  /Border>

       <Border ... /Border>

   </Grid>
</ScrollViewer>


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

4 Comments

Thanks. It still doesn't work. I finally made it work by changing the Height of the Grid to 1000 then it works.
Now I know the height of the grid has to be longer than the height of the UserControl.
set the Height to Auto
so as the grid grows out of the its container then you would see the scollbar appear

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.