How to anchor controls in WPF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    How to anchor controls in WPF

    I shifted this Question to .Net forum because no one's looking at it in XAML forum
    Anyone can tell me how can i anchor controls in WPF or Silverlight as it is done in Windows Forms Programming
  • nukefusion
    Recognized Expert New Member
    • Mar 2008
    • 221

    #2
    Originally posted by ThatThatGuy
    Anyone can tell me how can i anchor controls in WPF or Silverlight as it is done in Windows Forms Programming
    WPF introduces a significant change from the old WinForms method of control placement. The anchor property no longer exists.

    Ideally, with WPF, you would design your interfaces to flow and adapt to resizing by nesting them in one or more of the available layout controls, i.e. StackPanel, WrapPanel, Grid, etc.

    If you want to try and emulate old behaviour there are a couple of things you can do.

    If you really want to position controls with absolute coordinates, you can nest them within a Canvas control and you then set the attached properties Canvas.Left and Canvas.Top to position your element.

    If you want to dock controls, you can nest them in a DockPanel and use the DockPanel.Dock attached property to set the docked edge.

    Hope this helps.

    Comment

    Working...