WPF UserControl在运行时溢出父窗口

时间:2019-07-09 21:52:14

标签: c# wpf user-controls resize

我正在设置一个WPF应用程序,其中有一个带有单选按钮的标题,可通过更改活动的UserControl更改其下方网格的视图。我还动态地将窗口的高度和宽度设置为用户窗口高度的80%。当窗口显示我的用户控件时,该用户控件要么结束了网格的填充,要么网格正在切断用户控件

我将行高度设置为动态,并删除了用户控件的默认高度和宽度,但该行仍被切断。据我了解,用户控件应该只是自动填充网格的大小。

<Viewbox Stretch="UniformToFill">
<Grid Height="880" Width="960">
        <!--Seperate View Style -->
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="0" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ContentControl Content="{Binding }" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <ContentControl.Style>
                <Style TargetType="{x:Type ContentControl}">
            double FormatHeight = SystemParameters.PrimaryScreenHeight * .8;
            double FormatWidth = FormatHeight * 1.0909;
            InitializeComponent();

            this.Height = FormatHeight;
            this.Width = FormatWidth;
  <Grid Background="#EFEFEF" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Border x:Name="AlertHelperPanel" Margin="10,10,10,10" Background="White">
            <ListView Name="AlertNotifications" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                      Height="{Binding Path=ActualHeight, ElementName=AlertHelperPanel}" 
                      Width="{Binding Path=ActualWidth, ElementName=AlertHelperPanel}" 
                      ItemsSource="{Binding Alerts}"
                      MouseDoubleClick="details_OnMouseDoubleClick">
                <ListView.View>

1 个答案:

答案 0 :(得分:0)

显然,由于用户控件正在缩放但期望特定的宽高比,所以出现了此问题。删除视图框后,窗口大小将在不更改内部控件大小的情况下进行调整,这向我表明,这与usercontrol大小与window大小有关。在CS代码中调整了我的宽高比,直到其尺寸正确为止。