开发者

How do I anchor elements?

开发者 https://www.devze.com 2023-04-12 19:05 出处:网络
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开发者_如何学JAVAuse th

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

精彩评论

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

关注公众号