C
C#4d ago
GolemMan

wpf elements with a vertical alignment of top aren't exactly at the top and have a weird gap.

Hello, I have a window with the button at the top and I noticed that they aren't sticking to the top and have a weird gap in between the top and them, I believe it's most likely related to the grid but I can't find out why.
No description
78 Replies
GolemMan
GolemManOP4d ago
I'll make a quick github gist of the code rq
GolemMan
GolemManOP4d ago
Gist
MainWindow.xaml
GitHub Gist: instantly share code, notes, and snippets.
GolemMan
GolemManOP4d ago
I'm fairly new to wpf, sorry if this some really easy thing to change
ACiDCA7
ACiDCA74d ago
you can use the viual live tree to see what is causing the gap at top thats what the toolbar at the top is for
GolemMan
GolemManOP4d ago
could you explian me how exactly ? I mean I can see the different controlers and stuff but it doesn't show much
GolemMan
GolemManOP4d ago
also I found out that there is not only a gap but something that puts itself on top of everything making it so that margins don't work
No description
glhays
glhays4d ago
It may be the quick action bar causing just a visual. Try disabling it in the tools XAML Designer section
Buddy
Buddy4d ago
Please do not use the designer $rulesofwpf
MODiX
MODiX4d ago
Rules of WPF:

❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

✅ Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
✅ Rely upon XAML Hot Reload to design your app's UI at runtime
✅ Use layout controls (Grid, DockPanel, etc) to support proper resizing
✅ Use data binding to eliminate glue code and state synchronization issues
✅ Use collection controls and DataTemplate to dynamically create lists of controls
✅ Learn MVVM to create maintainable apps
✅ Use the Dispatcher to update controls from non-UI threads
✅ WPF's default controls can be easily modernized via $wpfuilibs
✅ Include relevant XAML, code-behind, and ViewModel code for questions when possible
Rules of WPF:

❌ Avoid the WPF Designer to eliminate a category of confusing bugs
❌ Don't rely on Margin as the primary tool for layouts
❌ Avoid writing UserControls or subclassing to extend a default control -- use Behaviors instead (Microsoft.Xaml.Behaviors.Wpf)

✅ Write XAML by hand and autoformat with "Ctrl K,D" or XAML Styler
✅ Rely upon XAML Hot Reload to design your app's UI at runtime
✅ Use layout controls (Grid, DockPanel, etc) to support proper resizing
✅ Use data binding to eliminate glue code and state synchronization issues
✅ Use collection controls and DataTemplate to dynamically create lists of controls
✅ Learn MVVM to create maintainable apps
✅ Use the Dispatcher to update controls from non-UI threads
✅ WPF's default controls can be easily modernized via $wpfuilibs
✅ Include relevant XAML, code-behind, and ViewModel code for questions when possible
Buddy
Buddy4d ago
Margin is the spacing between elements, it is not absolute position Please use the layout controls, such as Grid, DockPanel, StackPanel, etc.
GolemMan
GolemManOP4d ago
buh I really just choose wpf because it had that designer + code change and no weird docks and grid stuff
Buddy
Buddy4d ago
Use hot reload
GolemMan
GolemManOP4d ago
well thanks for the heads up
Buddy
Buddy4d ago
designer + code change
This is exactly what WPF is not You're describing WinForms
GolemMan
GolemManOP4d ago
ow okay
Buddy
Buddy4d ago
You should never use designer in XAML frameworks as they are horrible
GolemMan
GolemManOP4d ago
sorry for my lack of knowledge
Buddy
Buddy4d ago
WinForms is ancient and should not be used, but it does have a drag n drop style. However .. It still will fail if you resize the application WinForms also barely supports transparency
GolemMan
GolemManOP4d ago
ah well still I'm close to finishing that project I want to finish it before moving to avalonia or something else
Buddy
Buddy4d ago
Avalonia is XAML as well .. Soo And it does not have a designer at all. It does have a previewer but that is just to interact with the app. Not drag 'n drop elements / design with
GolemMan
GolemManOP4d ago
guh
Buddy
Buddy4d ago
WYSIWYG editors are not of this millennia, they all suck
GolemMan
GolemManOP4d ago
what would you recommend then
Buddy
Buddy4d ago
Well .. XAML? And to use hot reload just run your app and edit the XAML, you'll see the changes get reflected live while running the app
GolemMan
GolemManOP4d ago
mmmokay
Buddy
Buddy4d ago
and obviously to use the layout controls
glhays
glhays4d ago
And disable that quick actions bar
GolemMan
GolemManOP4d ago
yeah I'll try that thanks
Buddy
Buddy4d ago
and they exists in pretty much any UI framework Imagine if your monitor's center point is 500px, but what if I have a bigger screen and my center point is 1000px? Your center is not always other users center point. That's basically what the issue of using absolute positions (and without layout controls)
ACiDCA7
ACiDCA74d ago
sooo much hate here for the wpf designer..xD it isnt thaaat bad also hot reload also doesnt work always
Buddy
Buddy4d ago
Yes, it does work always. It might not if you use bad UI Frameworks like WInUI3 or .NET MAUI Try to resize an app that is made with purely the designer.
ACiDCA7
ACiDCA74d ago
easy you can do most stuff that you do in code in the propertywindow its a pain in the ass but it works
Buddy
Buddy4d ago
its a pain in the ass
Exactly. If you just learn XAML, making an app with the designer will be x3 slower And of course use hot reload as well Things such as window themes aren't reflected in the designer either
ACiDCA7
ACiDCA74d ago
i still stand on the opinion that hotreload isnt THE solution -designer supports designtime data, to show dummydata in running application you have often more work -some changes cant be hotreloaded -you need a test environment you can do it at least we do it with devexpress
Buddy
Buddy4d ago
Avalonia did good by not having a WYSIWYG editor. It is purely to interact with the app when a hot reload did not exist at the time, but it does exist now via a 3rd party library. devexpress .. That is paid?
ACiDCA7
ACiDCA74d ago
jea
Buddy
Buddy4d ago
You'd rather pay for something to see the theme in a designer than to use hot reload? Seems wasteful
ACiDCA7
ACiDCA74d ago
naa we have more uses just saying that we are using themes created with devexpress which we can also see in designer
Buddy
Buddy4d ago
With hot reload you can also change the code at runtime as well as the XAML
ACiDCA7
ACiDCA74d ago
just slam d:Theme=... in window root and designer will use that theme not all changes are hot reloadable
Buddy
Buddy4d ago
Sure, but rather that than have to rely on a designer that is broken and completely wrong and no live code change at all. If you want a decent WYSIWYG editor, check Uno. But I heard that is also quite bad.
ACiDCA7
ACiDCA74d ago
im not saying that there is no use for hot reload.. i use both at the same time.. i do the groundwork in the designer and then adjust stuff via hotreload.. and again... the designer for previewing things, doing touchups and so on isnt thaaat bad
GolemMan
GolemManOP4d ago
not to be mean or anything but can you two go in another channel ? kinda went off topic
Buddy
Buddy4d ago
It still is on topic, but yes. I won't argue further. Either way, I apologize. What buttons were misaligned?
GolemMan
GolemManOP4d ago
no worries thanks for you input
Buddy
Buddy4d ago
In the code that is
GolemMan
GolemManOP4d ago
it's not an alignment issue but just two buttons aren't really at the top
No description
GolemMan
GolemManOP4d ago
can't explain it very well sorry I'm trying to figure out what that is though
ACiDCA7
ACiDCA74d ago
you went do hard on rant that you didnt even notice that btn_OtherData Btn_OpenSettings dont even have margins
Buddy
Buddy4d ago
What names do they have?
GolemMan
GolemManOP4d ago
the ones AciDCA7 just sent
Buddy
Buddy4d ago
Other things do which may screw up alignment / positioning
GolemMan
GolemManOP4d ago
you can see in the designer both buttons are at the top as well
No description
ACiDCA7
ACiDCA74d ago
that is most likely your windowchrome
GolemMan
GolemManOP4d ago
what's that ?
ACiDCA7
ACiDCA74d ago
you tried to hide the windowtitlebar/border.. but you didnt hide everything the piece at the top is still a bit left of the windowcontainerstuff
Buddy
Buddy4d ago
I tried the exact same code, it is at the top for me.
No description
GolemMan
GolemManOP4d ago
ah I see
ACiDCA7
ACiDCA74d ago
what OS are you running
Buddy
Buddy4d ago
You mean version? WPF only supports one 😛
GolemMan
GolemManOP4d ago
windows 10
ACiDCA7
ACiDCA74d ago
stop being a dick..xD
GolemMan
GolemManOP4d ago
huh
Buddy
Buddy4d ago
<-- Windows 11 user here
GolemMan
GolemManOP4d ago
maybe windows 10 has that issue but not windows 10 ?
Buddy
Buddy4d ago
Do you have a spacing on other apps too or just this one?
GolemMan
GolemManOP4d ago
well it's my only wpf app but I guess I can make another project rq to see
glhays
glhays4d ago
same when I tested the gist as well. windows10
ACiDCA7
ACiDCA74d ago
i guess you guys were using net >5 golem are you using net framework or net >5 anyway... golem add this as window child <WindowChrome.WindowChrome> <WindowChrome CaptionHeight="0" ResizeBorderThickness="5" /> </WindowChrome.WindowChrome>
GolemMan
GolemManOP4d ago
sorry for the long delay but yeah I do uhh how do I check that ?
ACiDCA7
ACiDCA74d ago
No description
GolemMan
GolemManOP4d ago
was about to ask lol ty ayy that fixed it thanks you !!! and thanks you too everyone else for the help!
ACiDCA7
ACiDCA74d ago
nonono i want to have all the thanks for myself
GolemMan
GolemManOP4d ago
lolll
MODiX
MODiX4d ago
ACiDCA7
stop being a dick..xD
React with ❌ to remove this embed.
mikernet
mikernet3d ago
Uno Hot Design is actually pretty damn slick. Uno made designers great again. It embeds the designer into the running application in debug mode and you toggle it with the debug toolbar. Your changes are to the actual live application. The XAML designer revolution is coming, albeit for WinUI / Uno 😄 It's like designer and hot reload in one But I agree with the general sentiment. I was also on the "hot reload only" XAML wagon until a couple weeks ago.
Want results from more Discord servers?
Add your server