How can I resize a *
column in the XamDataGrid
? In this example, I cannot resize the department
column.
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);
}
}
}
See how no resizing cursor appears between the department
and salary
columns:
What do I have to do to be able to resize a *
column?
How can I have one column use all available space but still allow resizing?
Setting the department
field to Width="*"
prevents it from resizing. To enable resizing of this field it is necessary just remove the width setting in this column.
<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>
You can also try to set AutoFit="True"
whether the cells and labels will be sized to exactly without the need to scroll.
Question: How can I have one column use all available space but still allow resizing?
Answer: You can set Width="Auto"
for all columns except the one you want to be using all available space but still allow resizing. For this column don't set the Width
property.