Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF网格-调整窗口大小时如何保持列宽?_C#_.net_Wpf_Xaml - Fatal编程技术网

C# WPF网格-调整窗口大小时如何保持列宽?

C# WPF网格-调整窗口大小时如何保持列宽?,c#,.net,wpf,xaml,C#,.net,Wpf,Xaml,我有这个XAML标记 <Grid Name="ProductsGrid" Width="500"> <Grid.RowDefinitions> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Nam

我有这个XAML标记

<Grid Name="ProductsGrid" Width="500">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Name="ProductList" Width="*" />
            <ColumnDefinition Name="ProductInfo" Width="100" MinWidth="10" MaxWidth="100"/>
        </Grid.ColumnDefinitions>

当应用程序启动时,第二列为se至100“单位”宽

当窗口调整大小时,列会增长和收缩-它会保持与列1的比率,我认为这是我在WPF中应该发生的。因此,当应用程序启动时,窗口大小设置为500,第二列为总宽度的1/5。当应用程序调整大小时,它保持总宽度的1/5,但在本例中,我希望它保持在100个单位


有什么想法吗?

去掉网格的宽度,它正在固定网格的宽度,网格的宽度保持在100。。。如果要查看实际网格位置,请指定网格背景色

您可以将主窗口的初始宽度固定为100,并使网格不具有固定宽度,以允许所需的行为

试试这个:

<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"  Width="100" x:Name="MyWindow">
    <Grid Name="ProductsGrid">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Name="ProductList" Width="*" />
                <ColumnDefinition Name="ProductInfo" Width="100" MinWidth="10" MaxWidth="100"/>
            </Grid.ColumnDefinitions>

试试这个

<Grid Name="ProductsGrid"  ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Name="ProductList" Width="*" />
            <ColumnDefinition Name="ProductInfo" Width="100" MinWidth="10" MaxWidth="100"/>
        </Grid.ColumnDefinitions>
    </Grid>

我尝试了你的xaml,第二列保持100像素不变。在新的测试应用程序窗口中尝试。问题可能在这个xaml之外,也可能在网格的内容之内。
 private void mywindow_Loaded(object sender, RoutedEventArgs e)
            {
                this.Width = 500;
            }