WPF Scrollviewer在Usercontrol中不可见。
我正在使用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。
答案 0 :(得分:0)
ScrollViewer不会显示,因为您只有一个空的堆栈面板。尝试添加一些宽度或高度的项目,您应该看到滚动查看器。