24 Replies
You're going to have to share the code for this before anyone can advise
I mean all I did was start the project and add a button to it
but one second let me post the code
$rulesofwpf
you have a 387 pixel margin from the top of the app in the button there:
"0,387,0,0"
I am gonna assume you didn't type that xaml by hand to add the button but maybe I'm wrong there, it's all oddly specific numbers in the height, margin, width.
Where did you want the button to go?near the bottom left side
so I have to write everything by hand?
or just the layout part?
Broadly, it's easier to have a layout that works logically if you are hand-crafting the markup.
the top two ❌ points here essentially
okay
im doing a course from udemy
You'd be best learning out how to do some simple layouts with containers like grids, stackpanels and stuff, and then putting your controls and things inside of them. Sorry that's a bit vague, it's hard to outline where to start with it and i've been out of the WPF space for a bit
But here if you dropped the margin and changed vertical alignment might that be better?
yeah
so I thought it was drag and drop
but I guess I have to code everything
which is a pain
The designer does work like that but all it can/will do is place controls in a very fixed way that won't adapt if you resize the app
im making an app that is not resizable
Also the controls won't adapt well when you add more controls, but that's very much in your control.
That said the rules posted above very much come from a place of how to write good maintainable production WPF code. If you're just starting out, do what works best for you but just know that you can tweak the xaml by hand if it's not looking right
Like, here, you could just reduce that margin number a bit and it'd be onscreen
okay than ks
np!
Should I be using canvas to position my controls?
You could try it. I can't say I've ever tried it.
I think it works well for a world of absolute positioning rather than relative
how did you move around everything?
Do you mean like structuring the layout?
yes
It's been a fair few years since I did WPF but Dockpanels, Stackpanels, Grids and then small adjustments to margins and padding mostly I think.
I don't have any good examples to hand sadly
GitHub
WPF-Samples/Sample Applications at main · microsoft/WPF-Samples
Repository for WPF related samples. Contribute to microsoft/WPF-Samples development by creating an account on GitHub.
Some of those look like they might be good small examples you could play with