WPF Scrollviewer在用户控件内不可见。
我正在使用PRISM体系结构。
我在usercontrol中有一个scrollviewer,scrollviewer包含一个stackpanel。
<UserControl x:Class="SomeView" 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"
mc:Ignorable="d" >
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</UserControl.Resources>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<StackPanel>
<TextBlock Text="Initialize" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<StackPanel Orientation="Horizontal">
<Label Content="Left"/>
<ComboBox ItemsSource="{Binding LeftComboItems}" SelectedItem="{Binding LeftSelectedItem}" />
<Label Content="Right"/>
<ComboBox ItemsSource="{Binding RightComboItems}" SelectedItem="{Binding RightSelectedItem}"/>
<Label/>
<Button Content="Save" Command="{Binding SaveCommand}"/>
</StackPanel>
<StackPanel Visibility="{Binding IsVisible,Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid>
跳过列定义
<StackPanel Grid.Column="1" Grid.ColumnSpan="2">
<Label Content="Left" />
<DataGrid ItemsSource="{Binding LeftDataGrid}" AutoGenerateColumns="False" ColumnWidth="*" Grid.Column="2" >
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding ID}" />
<DataGridTextColumn Header="Name" Binding="{Binding Name}" />
</DataGrid.Columns>
</DataGrid>
</StackPanel>
<StackPanel Grid.Column="4" Grid.ColumnSpan="2">
<Label Content="Left Grid" />
<DataGrid ItemsSource="{Binding RightDataGrid, Mode=OneWay}" AutoGenerateColumns="False" ColumnWidth="*" CanUserAddRows="False" CanUserDeleteRows="False" >
<DataGridTextColumn Header="ID" Binding="{Binding id}" />
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
</DataGrid>
</StackPanel>
</StackPanel>
</Grid>
</StackPanel>
</ScrollViewer>
LeftComboItems,RightComboItems是字符串类型的Observable Collections。
最佳答案
卸下StackPanel(使用网格/面板)或为StackPanel设置一些较大的高度。
关于c# - Scrollviewer在用户控件WPF中不可见,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20849719/