DataGrid ColumnWidth在DataTemplate中忽略行详细信息的属性 [英] DataGrid ColumnWidth Property ignored in DataTemplate for row details

查看:177
本文介绍了DataGrid ColumnWidth在DataTemplate中忽略行详细信息的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是UserControl,显示我的应用程序的详细信息,您可以看到 ColumnWidth 属性显式设置为 * 。我还尝试从 DataGridTextColumn 中设置宽度属性。

This is the UserControl that displays the details from my application and as you can see the ColumnWidth Property is explicit set to *. I also tried to set the Width property from the DataGridTextColumn.

<UserControl x:Class="WpfUserInterface.MyDetailsView"
         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" Height="185" d:DesignWidth="480">
    <Grid>
        <DataGrid ColumnWidth="*" Margin="10">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Column1"/>
                <DataGridTextColumn Header="Column2"/>
                <DataGridTextColumn Header="Column3"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</UserControl>

这是仅包含DataGrid的主窗口。

This is the main window that only contains the DataGrid.

<Window x:Class="WpfUserInterface.Window"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window" Height="306" Width="453">
    <Grid>
        <DataGrid ColumnWidth="*">
            <DataGrid.Columns>
                <DataGridTextColumn Header="ParentColumn1"/>
                <DataGridTextColumn Header="ParentColumn2"/>
                <DataGridTextColumn Header="ParentColumn3"/>
            </DataGrid.Columns>
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <MyDetailsView/>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
        </DataGrid>
    </Grid>
</Window>

这是运行应用程序时在屏幕上显示的内容,并在父DataGrid中选择一行。

This is what shows up on the screen when you run the application and select a row in the parent DataGrid.

当我将 MyDetailsView 中的DataGrid的宽度设置为一个指定的值,如400,这些列的大小是完美的,但这不是一个选项。有没有办法解决这个问题?一个解决方法?

When I set the width of the DataGrid in the MyDetailsView to a specified value like 400 the columns are sized perfect but this is not an option. Is there any way to solve this problem? A workaround?

推荐答案

我知道这个问题在一年前被问到,但是我一直面对同样的问题,我发现这个解决方案:

I know this question was asked about a year ago, but I've been facing the same problem and I've found out this solution:

 this.dgrData.Columns[0].Width = new DataGridLength(1, DataGridLengthUnitType.Star);
 this.dgrData.Columns[1].Width = new DataGridLength(1, DataGridLengthUnitType.Star);
 ...

希望对某人有帮助。

这篇关于DataGrid ColumnWidth在DataTemplate中忽略行详细信息的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆