我正在试图弄清楚如何让我ContentControl正确地水平滚动(此刻垂直方向).通过正确我的意思是我希望看到内容伸展(无限扩展),同时具有滚动条出现的最小尺寸,以使内容不会溢出该ContentControl区域,所以这里是一个快速介绍:
主窗口以这种方式构造:
ContentControl的模板:
实际问题是ContentControl在您调整窗口大小时会增长,但不会随着窗口大小调整而缩小.
主视图XAML(为清晰起见截断):
<ScrollViewer Grid.Row="5" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ContentControl Grid.Row="5" Background="Transparent" Focusable="False" Margin="0,5,0,0"
Content="{Binding CurrentSection}" ContentTemplateSelector="{StaticResource templateSelector}/>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
Tempate XAML(为清晰起见截断):
<Grid>
...
<ItemsControl Grid.Row="4" ItemsSource="{Binding Data.QualifyingDistributionsDividends}" x:Name="QualifyingItemsControl">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid x:Name="DTLayoutGrid">
...
<Grid Grid.Row="1" x:Name="DataLayout" Width="{Binding ElementName=DTLayoutGrid, Path=ActualWidth}" HorizontalAlignment="Stretch">
...
<DataGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="8" HorizontalScrollBarVisibility="Disabled"
ItemsSource="{Binding Payments}" Style="{StaticResource DataGridStyle}" CellStyle="{StaticResource DataGridNormalCellStyle}">
</DataGrid>
</Grid>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Run Code Online (Sandbox Code Playgroud)
那会发生什么?Datagrid假设整个宽度DataTemplate(以及其设置为DataTemplates大小的底层控件,然后*列假定所有空的空间.当您尝试调整保存此代码的整个窗口时,它将正确生长,扩展*列但似乎缩小没有"注册",它保持你扩展它的大小,在其上应用滚动条并忘记它.
我已经试过到目前为止是设置宽度ItemsControl,其潜在的父母喜欢网等,还设置大小 …