Hi, I'm trying to "hide" a column based on a bool property in my View Model, I want to accomplish this by setting DataGridColumn width property to "0" when hidden (false) and "2*" when visible (true). I tried hard coding those values and it worked, but when using the binding converter, it only applies the changes to the data rows, not the header row.
Of course my converter is well imported as I'm able to debug it, here is the code:
public class ColumnWidthBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType == typeof(double))
{
return (bool) value ? 150 : 0;
}
return (bool) value ? new GridLength(2, GridUnitType.Star) : new GridLength(0, GridUnitType.Absolute);
}
I tried to consider the case where the Header row asks for Double instead of GridLength as a value type, but haven't succeeded.
When trying to set the width programatically for a third hidden column, I end up with 3 header columns and 2 data columns.
Header creation event tirggered in 2 occurences: on Columns Property Change and OnParentSet method. I suggest that binding the columns. if you want to change the number of columns.
Hi, I'm trying to "hide" a column based on a bool property in my View Model, I want to accomplish this by setting DataGridColumn width property to "0" when hidden (false) and "2*" when visible (true). I tried hard coding those values and it worked, but when using the binding converter, it only applies the changes to the data rows, not the header row.
Of course my converter is well imported as I'm able to debug it, here is the code:
I tried to consider the case where the Header row asks for Double instead of GridLength as a value type, but haven't succeeded.
When trying to set the width programatically for a third hidden column, I end up with 3 header columns and 2 data columns.