【发布时间】:2021-04-27 16:21:19
【问题描述】:
我已经实现了一个用户控件,它在 ScrollViewer 中包含一个网格。后面没有功能代码。如果在应用程序中使用 XAML(见下文)(因此在 <Window></Window> 之间),它会按预期工作。如果行高足够大并且可以向上滚动较低的行,则会出现垂直滚动条。但是,如果将完全相同的 XAML 用作用户控件的一部分(因此在 <UserControl></UserControl> 之间),它的工作方式相同,但滚动条被禁用。 ScrollViewer 在检查时显示 IsEnabled 为真。知道为什么无法选择此控件吗?
<Canvas Name="MyCanvas">
<Canvas Name="GridHeaderCanvas"
Background="Black"
Width="345"
Height="480"
Canvas.Top="0">
<Label Content="Add" Background="BlanchedAlmond" HorizontalAlignment="Center" Width="35" Height="25" Canvas.Top="3" Canvas.Left="3"></Label>
<Label Content="Name" Background="PowderBlue" HorizontalContentAlignment="Center" Width="245" Height="25" Canvas.Top="3" Canvas.Left="41"></Label>
<Label Content="Val" Background="PowderBlue" HorizontalContentAlignment="Center" Width="35" Height="25" Canvas.Top="3" Canvas.Left="290"></Label>
<ScrollViewer x:Name="MyScrollViewer"
Canvas.Top="30"
Canvas.Left="3"
Height="440"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<Grid x:Name="GridCanvas"
Background="Black">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="35" />
<ColumnDefinition Width="245" />
<ColumnDefinition Width="35" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="200" />
<RowDefinition Height="200" />
<RowDefinition Height="200" />
<RowDefinition Height="200" />
</Grid.RowDefinitions>
<Label Content="Val0" Background="PowderBlue" Grid.Column="0" Grid.Row="0"></Label>
<Label Content="Val0" Background="PowderBlue" Grid.Column="1" Grid.Row="0"></Label>
<Label Content="Val0" Background="PowderBlue" Grid.Column="2" Grid.Row="0"></Label>
<Label Content="Val1" Background="Pink" Grid.Column="0" Grid.Row="1"></Label>
<Label Content="Val1" Background="Pink" Grid.Column="1" Grid.Row="1"></Label>
<Label Content="Val1" Background="Pink" Grid.Column="2" Grid.Row="1"></Label>
<Label Content="Val2" Background="Yellow" Grid.Column="0" Grid.Row="2"></Label>
<Label Content="Val2" Background="Yellow" Grid.Column="1" Grid.Row="2"></Label>
<Label Content="Val2" Background="Yellow" Grid.Column="2" Grid.Row="2"></Label>
<Label Content="Val3" Background="Pink" Grid.Column="0" Grid.Row="3"></Label>
<Label Content="Val3" Background="Pink" Grid.Column="1" Grid.Row="3"></Label>
<Label Content="Val3" Background="Pink" Grid.Column="2" Grid.Row="3"></Label>
</Grid>
</ScrollViewer>
</Canvas>
<Canvas Name="ComponentCanvas"
Width="300"
Height="480"
Background="LightSkyBlue"
Canvas.Top="0"
Canvas.Left="350">
<StackPanel
Name="ControlPanel"
Canvas.Top="10"
Canvas.Left="10">
</StackPanel>
</Canvas>
</Canvas>
【问题讨论】:
标签: xaml scroll user-controls scrollbar