a little background first. We have some legacy UI controls which are defined in text files and we are parsing the same text files to create xaml.
One of the controls is similar to a WPF ListView and the text file can hold a collection of columns which have their own properties. One of these properties denotes if a column is to have a fixed width, which WPF does not automatically provide.
A picture speaks a thousand words, so here is an example of a parsed file containing a ListView with four columns:
For simplicities sake I have used coloring for demonstration purposes. The first column with the red text, is the column with a fixed width.
To achieve this, during the parsing, each GridViewColumnHeader receives a Style, which in itself can be modified, depending on the flags (i.e. "IsFixed") contained in the properties for that column.
In order to fix the width of a column, I have created a Style which adds the MinWidth and MaxWidth setters to the style. Please note that the ColumnResize is a custom enum.
private void _ModifyColumnResize(ref Style style, ColumnResize columnResize, int width)
{
if (columnResize == ColumnResize.IsFixed)
{
var minWidth = new Setter(MinWidthProperty, (double)width);
var maxWidth = new Setter(MaxWidthProperty, (double)width);
var fixedColor = new Setter(ForegroundProperty, Brushes.Red);
style.Setters.Add(minWidth);
style.Setters.Add(maxWidth);
style.Setters.Add(fixedColor);
}
}
This all seems to work fine, double-clicking on the column grip does not automatically change the width to that of its content (as with the other three columns). The problem is if I click on the gripper then attempt to resize, then I see this:
As you can see, the column itself has the same width, but to the left and right of the column, spacing appears - which is not wished.
My question is, can I stop this behavior through styling? Ideally I would not like to have the gripper visible for a column which is not to allow resizing, but I am unsure as to how to accomplish that as the Style would be created in code-behind (during the parsing) and not in xaml.
Thanks for your time!