myUserControl = new myUserControl(this);
myUserControl.Margin = new Thickness(300, 0, -300, 0);
mainDockPanel.Children.Add(myUserControl);
DockPanel.SetDock(myUserControl, Dock.Top);
I would like to have myUserControl at center of开发者_运维技巧 the screen, even when the user maximize the window. I guess I could do it if the code above worked u.U Any ideias? Thank you.
Why don't you just use HorizontalAlignment="Center"
and VerticalAlignment="Center"
with a fixed Width or a fixed Margin?
You can also wrap it in a stretching control like a Grid, something like:
myUserControl = new myUserControl(this);
Grid grid = new Grid();
myUserControl.HorizontalAlignment = HorizontalAlignment.Center;
myUserControl.VerticalAlignment = VerticalAlignment.Center;
grid.Children.Add(myUserControl);
mainDockPanel.Children.Add(grid);
DockPanel.SetDock(grid, Dock.Top);
精彩评论