WPF WrapPanel Horizo​​ntalContentAlignment

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13966952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:42:48  来源:igfitidea点击:

WPF WrapPanel HorizontalContentAlignment

wpfalignmentwrappanel

提问by Reyn

Is there a way to make all item in WrapPanel alignment to center?

有没有办法让 WrapPanel 中的所有项目对齐到中心?

WrapPanel Normal Behavior

WrapPanel 正常行为

|1234567  |
|890      |

Desired Behavior

期望的行为

| 1234567 |
|   890   |

Possible duplicate link

可能的重复链接

I just don't understand how to use the code on the answer (on link).

我只是不明白如何使用答案中的代码(在链接上)。

采纳答案by Ramin

The link is a custom WrapPanel. just copy it into an empty class and be sure to set all the usingclasses at the first lines.

该链接是一个自定义的 WrapPanel。只需将其复制到一个空类中,并确保using在第一行设置所有类。

Use this custom panel as you use a normal WrapPanel. (in Xaml is a little bit different). in this panel there is an extra propert: HorizontalContentAlignment. Its default value is HorizontalAlignment.Left. You should set HorizontalAlignment=HorizontalAlignment.Center.

像使用普通 WrapPanel 一样使用此自定义面板。(在 Xaml 中有点不同)。在这个面板中有一个额外的属性:HorizontalContentAlignment。其默认值为HorizontalAlignment.Left。你应该设置HorizontalAlignment=HorizontalAlignment.Center.

There is no need to deal with MeasureOverride or ArrangeOverride methods.

无需处理 MeasureOverride 或ArrangeOverride 方法。