XamDataGrid 调整星形列的大小

XamDataGrid resize star column

如何调整 XamDataGrid* 列的大小?在此示例中,我无法调整 department 列的大小。


MWE:MainWindow.xaml

<Window x:Class="GridPerformAutoSize.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:igWPF="http://schemas.infragistics.com/xaml/wpf"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Title="MainWindow"
        Width="800"
        Height="450"
        mc:Ignorable="d">
    <Grid>

        <igWPF:XamDataGrid x:Name="dataGrid">
            <igWPF:XamDataGrid.FieldLayoutSettings>
                <igWPF:FieldLayoutSettings AutoGenerateFields="False" />
            </igWPF:XamDataGrid.FieldLayoutSettings>
            <igWPF:XamDataGrid.FieldLayouts>
                <igWPF:FieldLayout>
                    <igWPF:Field Name="name" />
                    <igWPF:Field Name="department" Width="*" AllowResize="True" />
                    <igWPF:Field Name="salary" />
                    <igWPF:Field Name="email" />
                </igWPF:FieldLayout>
            </igWPF:XamDataGrid.FieldLayouts>
        </igWPF:XamDataGrid>

    </Grid>
</Window>

MainWindow.xaml.cs

using System.Linq;

namespace GridPerformAutoSize
{
    public class Person
    {
        public string name { get; set; }
        public string department { get; set; }
        public string salary { get; set; }
        public string email { get; set; }
    }
    
    public partial class MainWindow
    {
        public MainWindow()
        {
            this.InitializeComponent();

            this.dataGrid.DataSource = Enumerable.Repeat(new Person() { department = "HR", email = "john@hotmail.com", name = "John Smith", salary = "52500" }, 5);
        }
    }
}

查看 departmentsalary 列之间如何没有出现调整大小光标:


我需要做什么才能调整 * 列的大小?

如何让一列使用所有可用的 space 但仍允许调整大小?

department 字段设置为 Width="*" 可防止其调整大小。要启用此字段的大小调整,只需删除此列中的宽度设置即可。

<igWPF:XamDataGrid x:Name="dataGrid" AutoFit="True">
    <igWPF:XamDataGrid.FieldLayoutSettings>
        <igWPF:FieldLayoutSettings AutoGenerateFields="False" AutoFitMode="Always" />
    </igWPF:XamDataGrid.FieldLayoutSettings>
    <igWPF:XamDataGrid.FieldLayouts>
        <igWPF:FieldLayout>
            <igWPF:Field Name="name" />
            <igWPF:Field Name="department" />
            <igWPF:Field Name="salary" />
            <igWPF:Field Name="email" />
        </igWPF:FieldLayout>
    </igWPF:XamDataGrid.FieldLayouts>
</igWPF:XamDataGrid>

您也可以尝试设置 AutoFit="True" 单元格和标签的大小是否会在不需要滚动的情况下精确调整。

问题:如何让一列使用所有可用的space但仍然允许调整大小?

答案:您可以为所有列设置 Width="Auto",除了您想要使用的所有可用列 space 但仍然允许调整大小。对于此列,不要设置 Width 属性.