繁体   English   中英

UserControl 中的 C# WPF ScrollViewer 不起作用

[英]C# WPF ScrollViewer in UserControl doesn't work

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

我想要的是在此控件显示时显示 ScrollBar 并且用户可以滚动查看内容。

但是现在滚动条不会显示......

有人可以帮忙吗? 谢谢。

您不能直接在Grid上使用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>


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM