我有一个带ContentControl的页面。 ContentControl动态设置为UserControl,当前只包含DataGrid。发生这种情况时,会调整页面大小以适应DataGrid的内容,这恰好会使页面离开屏幕。
如果我将页面宽度从“自动”更改为硬编码值,则在动态设置ContentControl时页面宽度不会更改。这是我想要的行为。但是,这也意味着当用户手动拖动窗口变大时,窗口的内容将不会扩展到比我设置的硬编码宽度值更大的范围。
如何在设置ContentControl时使页面保持相同的大小,同时在用户增加窗口大小时仍允许页面增长?
<Page x:Class="SageWpf.Views.ShellView"
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" Title="ShellView" MinHeight="450" MinWidth="800">
<Grid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Page, AncestorLevel=1}, Path=Width}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="Black" BorderThickness="2" Width="193">
<StackPanel Orientation="Vertical" Width="188">
<Button x:Name="ItemsScreen" FontSize="28" Height="65" Margin="1" Opacity="1">Items</Button>
<Button x:Name="CheckoutScreen" FontSize="28" Height="65" Margin="1" Opacity="1">Checkout</Button>
</StackPanel>
</Border>
<ContentControl x:Name="ActiveItem" Grid.IsSharedSizeScope="True" Grid.Column="1"></ContentControl>
</Grid>
</Page>
正如您所看到的,我的MinWidth为800,并且我希望在单击CheckoutScreen按钮时页面保持此宽度(如上所述,它将ContentControl加载包含DataGrid的视图)。 / p>
答案 0 :(得分:0)
您可以使用类似的东西让窗口保持用户可调整大小,但不能由控件本身调整大小。
<Grid ScrollViewer.VerticalScrollBarVisibility="Auto">