Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UserControl中的C#WPF ScrollViewer不';行不通_C#_Wpf_Wpf Controls - Fatal编程技术网

UserControl中的C#WPF ScrollViewer不';行不通

UserControl中的C#WPF ScrollViewer不';行不通,c#,wpf,wpf-controls,C#,Wpf,Wpf Controls,我需要一些帮助来使用我的ScollerViewer。这是我的密码: <UserControl x:Class="ConfigUI.Views.ProfileListView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

我需要一些帮助来使用我的ScollerViewer。这是我的密码:

<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>

我想要的是当这个控件显示时显示一个滚动条,用户可以滚动查看内容

但是现在滚动条不会显示


有人能帮忙吗?谢谢。

您不能直接在
网格上使用
ScrollViewer

试试这个结构


<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>




@Clint,试过了。仍然不起作用。请告诉我下面的答案是否有效,谢谢。它仍然不起作用。通过将网格的高度更改为1000,我最终使其正常工作。现在我知道网格的高度必须大于用户控件的高度。将高度设置为Autoso,当网格从其容器中生长出来时,您将看到scollbar出现