c# - UserControl 中的 C# WPF ScrollViewer 不起作用
问题描述
我的 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。
但是现在滚动条不会显示...
有人可以帮忙吗?谢谢。
解决方案
你不能ScrollViewer
直接Grid
拥有
试试这个结构
<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>
推荐阅读
- android - 当点击原生 android 后台服务通知时,Flutter 应用程序不会进入前台
- android-emulator - AMD/Win 10 上的 Android 模拟器
- java - 使用 UTF-16 将文本绘制到画布
- javascript - 复选框onCheck在javascript React native中无法正常工作
- html - 是否可以使用 HTML5 文件上传将文件从共享点位置上传/选择到应用程序?
- c# - CMD Copy 命令未通过 C# 正确执行
- python - 搜索每个值时,发送 POST 请求时输出为空列表
- jenkins - Groovy 子字符串 Jenkinsfile
- javascript - onclick 调用显示错误的函数:“返回是关键字”
- terraform - 为什么 Terraform 要再次创建自定义属性?