开发者

WPF - collapsing grid cells

开发者 https://www.devze.com 2023-02-05 01:12 出处:网络
I\'m having some problems with the layout of buttons on a screen. There are a number of buttons with the visibility set to collapsed depending on certain criteria.

I'm having some problems with the layout of buttons on a screen. There are a number of buttons with the visibility set to collapsed depending on certain criteria.

Anyway, with the buttons sitting in a stackpanel, the contents determine the width of the buttons. Because these should share the same size, I put them in a grid where the columns are using the SharedSizeGroup.

Having done this, buttons now all share the same width, t开发者_C百科he smallest width needed to display the button with the largest content. What it does mean though is that buttons don't display at the required position.

That is - assume five buttons in columns 0-4 where the first button is collapsed, buttons should ideally all shift to the left so that they always occupy space left to right. Is there any way I can accomplish this or, if not, how can I get buttons in a stackpanel to share the same width?

Any help is much appreciated.


You can wrap your buttons with individual grids and use that to set a shared size, the scope should be the stackpanel. Then control the visibility of the individual grids instead of the buttons, this is a bit messy though.

Edit: This is probably what you need:

    <UniformGrid Rows="1" HorizontalAlignment="Left">
            ...
0

精彩评论

暂无评论...
验证码 换一张
取 消