开发者

Programatically setting Horizontal alignment of Dock Panel

So far I have:

myDockPanel.SetValue(HorizontalAlignmentProperty, TextAlignment.Center);

I know TextAlignment.Center is not right. Does anyone know what this shou开发者_运维知识库ld be?


myDockPanel.HorizontalAlignment = HorizontalAlignment.Center;


The HorizontalAlignment property as defined by a DockPanel (and all FrameworkElement) takes a HorizontalAlignment for values. It should be:

myDockPanel.SetValue(DockPanel.HorizontalAlignmentProperty, HorizontalAlignment.Center);


There is no "Horizontal Content Alignment" property for the DockPanel control. If you intend to set the HorizontalAlignment property instead, then you could either use

myDockPanel.HorizontalAlignment = HorizontalAlignment.Center;

or

myDockPanel.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);

which are do pretty much the same thing since the property setter for the HorizontalAlignement (first example) calls the SetValue on the object (the second approach).

Just make sure you have a using statement for System.Windows namespace.

Hope this helps :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜