Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Star width column collapse to minimal size when Column header is hidden #221

Open
Al12rs opened this issue Oct 5, 2023 · 1 comment

Comments

@Al12rs
Copy link

Al12rs commented Oct 5, 2023

If I set the headers to hidden using either ShowColumnHeaders="False" or by some other method like setting the height of the header to 0, this collapses the column to minimal size if the column with is set to Star.

Images for illustrating the problem,
With Header visible:
image
The cells width expands to use the entire available horizontal space, as is the wanted behaviour.

When header is hidden:
image
The cells with is cut off to what I assume is the MinWidth of either the column or the item.

This is not the wanted behaviour. I expect this is caused by some width calculation involving the header width, which fails in case the header is hidden.

I'll include the code I used to to sets up the columns:

Code
    public HierarchicalTreeDataGridSource<ITreeDataGridSourceFileNode> Tree => new(GetTreeData())
    {
        Columns =
        {
            new HierarchicalExpanderColumn<ITreeDataGridSourceFileNode>(
                new TextColumn<ITreeDataGridSourceFileNode,string>("With Header",
                    x => x.FileName.ToString(),
                    width: new GridLength(1, GridUnitType.Star)
                    ),
                x => x.Children)
        }
    };
    protected virtual ITreeDataGridSourceFileNode GetTreeData() => CreateTestTree();

    private static ITreeDataGridSourceFileNode CreateTestTree()
    {
        var fileEntries = new Dictionary<RelativePath, int>
        {
            { new RelativePath("Some very long file name that takes most of the screen and should show .bsa"), 1 },
            { new RelativePath("BWS - Textures.bsa"), 2 },
            { new RelativePath("Readme-BWS.txt"), 3 },
            { new RelativePath("Textures/greenBlade.dds"), 4 },
            { new RelativePath("Textures/greenBlade_n.dds"), 5 },
            { new RelativePath("Textures/greenHilt.dds"), 6 },
            { new RelativePath("Textures/Armors/greenArmor.dds"), 7 },
            { new RelativePath("Textures/Armors/greenBlade.dds"), 8 },
            { new RelativePath("Textures/Armors/greenHilt.dds"), 9 },
            { new RelativePath("Meshes/greenBlade.nif"), 10 }
        };

        var tree = FileTreeNode<RelativePath, int>.CreateTree(fileEntries);
        return TreeDataGridSourceFileNode<RelativePath, int>.FromFileTree(tree);
    }

Axaml View code:

<TreeDataGrid ShowColumnHeaders="True" x:Name="ModContentTreeDataGrid">
@Sewer56
Copy link

Sewer56 commented Mar 25, 2024

Here's a silly workaround in the meantime.

In your view:

<TreeDataGrid x:Name="ModFilesTreeDataGrid" Width="1"> <!-- 👈 Set a width to positive number -->

In your view code behind:

public YourViewWithGrid()
{
    InitializeComponent();
    this.WhenActivated(disposables =>
    {
        // Do something to update the TreeDataGrid Source
        this.WhenAnyValue(view => view.ViewModel)
            .WhereNotNull()
            .Do(PopulateFromViewModel)
            .Subscribe()
            .DisposeWith(disposables);
        
        // Reset the control width back to NaN, to default it back as if no
        // width was specified.
        ModFilesTreeDataGrid.Width = double.NaN;
    });
}

This forces a recalculation of the columns, leading to a corrected width.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants