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 :)
精彩评论