[英]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.