开发者

How do I anchor elements?

I am use to working with windows forms, but recently I had started to work on WPF.

But I got into trouble when trying to anchor elements, the only solution I found online was to 开发者_如何学JAVA use the Dock element.

(It hadn't worked) On top of that I want some of my elements to behave like the anchor=right,left, button.

How can I do so?(for a tab control).


There is no "anchoring" in WPF like there was in WinForms. WPF has many options to control your layout and uses a combination of layout containers: DockPanel, Grid, StackPanel, etc. And layout attributes like HorizontalAlignment, VerticalAlignment, etc.

I would suggest that you read up on things on the layout containers, DockPanel, Grid, and StackPanel being the most popular (at least in my experience).

On the upside, I've personally found the layout system in WPF to much better and powerful than WinForms, once you get the hang of it.


Use Margin (not really needed), HorizontalAlignment="Stretch" and HorizontalAlignment="Stretch"

EDIT

You drag/drop a control and then right-click the control. Select Reset Layout -> All. Then set or drag the margins. Note that this behavior might be different depending on the container control.

You can click the arrows between the control and its container to toggle between fixed size and margins (docking)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜