C
C#14mo ago
DevDooz

❔ WPF Toolbox in visual does not autofill

Hello friends, I have a problem in Visual Studio 2022, when creating a WPF or WPF (Net Framework) template, when I enter the solution and use the toolbox to add components to the window I get that there are no usable controls In this group, I can add them from [Choose Toolbox Elements] from the Tools menu but when I leave the project and reopen it, the components I select are removed (Note: I was going to take a photo of the menu where I select the WPF elements but I got this thing that you see in the photo), as you can see I have the option for Visual to autofill the toolbox active but even if activated or deactivated nothing happens and I reinstalled the .NET desktop development package, I'm learning to start in my C# course and I reached the Graphical Interface part but now with this problem I cannot advance since the course does not work on this part with code from scratch. I would really appreciate your help and thank you in advance.
No description
No description
No description
44 Replies
Buddy
Buddy14mo ago
You should not use the toolbox for WPF The designer is terrible and causes layout issues. Please use the XAML to design your app as well as take use of hot reload
DevDooz
DevDoozOP14mo ago
How is it used? I'm doing a course on YouTube and that's what the programmer uses (I emphasize that his video is from 2019)
Buddy
Buddy14mo ago
XAML is similar to how web developers use HTML, except it's an all-in-one kind of language. Both styling, design / layout, and code binding is written in XAML.
sibber
sibber14mo ago
you write the xaml while your app is running and see the changes on the actual app
DevDooz
DevDoozOP14mo ago
Your suggestions are advanced for my information about visual and this for now, here I leave the video that I was watching about WPF and if you want you can fast forward it and see something (It is in Spanish but the detail is that you see what he does)
Buddy
Buddy14mo ago
1. Do not use designer 2. Use XAML 3. Do not use the designer
sibber
sibber14mo ago
you can still follow the video just whenever they use the designer you write it out yourself
DevDooz
DevDoozOP14mo ago
Do you suggest that I learn the WPF syntax?
DevDooz
DevDoozOP14mo ago
pildorasinformaticas
YouTube
Curso C#. WPF Interfaces gráficas I. Vídeo 72
Comenzamos con este vídeo a ver las interfaces gráficas con C#. Utilizamos la API de .NET: el "WPF", sustituto de Windows Forms para crear interfaces. Para más cursos, ejercicios y manuales visita: www.pildorasinformaticas.es
Buddy
Buddy14mo ago
Yes This is one of the reasons I hate YouTube courses, they only teach people bad habits. No actual useful information is given.
DevDooz
DevDoozOP14mo ago
Is it in the NET API?
Buddy
Buddy14mo ago
Take use of intellisense, but they have docs of each control. Not really any "tutorial" for it. It's easy to learn XAML, just the advanced parts are bindings and styling.
sibber
sibber14mo ago
theres https://wpf-tutorial.com/ which is pretty good
DevDooz
DevDoozOP14mo ago
Where can I download that pdf in Spanish for free?
Buddy
Buddy14mo ago
You seem to know English already?
Buddy
Buddy14mo ago
No description
Buddy
Buddy14mo ago
scroll down bud
DevDooz
DevDoozOP14mo ago
I literally have the translator open in another window Thank you very much for your help
sibber
sibber14mo ago
pretty good translator
br4kejet
br4kejet14mo ago
I've used the designer for years and have never encountered any kind of issue except for the VS2022 designer having a 1 pixel offset on everything what kind of issues have you gotten?
Buddy
Buddy14mo ago
$rulesofwpf
MODiX
MODiX14mo 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
Buddy14mo ago
- ❌ Avoid the WPF Designer to eliminate a category of confusing bugs - ❌ Don't rely on Margin as the primary tool for layouts Designer uses Margin as the primary tool of doing layouts Margin is the spacing between elements, it isn't absolute position
br4kejet
br4kejet14mo ago
I can kinda get that part for making apps on different DPI monitors, but apart from that I don't see anything wrong with it
Buddy
Buddy14mo ago
Try resizing your application and see how it goes 😉
br4kejet
br4kejet14mo ago
In the designer?
Buddy
Buddy14mo ago
No?
br4kejet
br4kejet14mo ago
Oh while it's running... well they resize just fine I don't blindly only use margins though, I use stack panels, dock panels, grid rows/columns, etc. Margins are just handy sometimes
Buddy
Buddy14mo ago
Exactly. Let me see your XAML
br4kejet
br4kejet14mo ago
Mainly when I can't figure out how else to do something
Buddy
Buddy14mo ago
Designer uses Margin Which is the reason why you should never use Designer as well as it isn't the actual preview Please use hot reload, don't use designer
br4kejet
br4kejet14mo ago
Yeah but you can use the gizmos to do non-margin based layouts like clicking the things that toggle vertical/horizontal alignment I can#'t really find anything specific to share as an example I currently only use margins to make the borders between controls work I use 1 pixel borders between panels instead of large gaps Wait i found something
Buddy
Buddy14mo ago
Yeah, please don't recommend using designer. Even if you personally have no issues with it. It shouldn't be a designer but a "preview".
Buddy
Buddy14mo ago
You don't use the designer meaning drag n drop
br4kejet
br4kejet14mo ago
I mean I do but if you say so... I use the designer to get an initial layout, then do some XAML work to get finer details
br4kejet
br4kejet14mo ago
not sure what you call this thing but it toggles the horizontal alignment of the selected control, and then you can just drag it to the edge of the parent and the designer automatically removes the margin at that point
No description
br4kejet
br4kejet14mo ago
then there's also the left and top bars when you select a component inside a Grid which lets you create a row/column at the mouse cursor which is convenient instead of writing like 5 lines of XAML
Buddy
Buddy14mo ago
You use the designer as a preview it seems, not as you would in windows forms that's the point. Designer uses Margins.
br4kejet
br4kejet14mo ago
For the most part yeah
sibber
sibber14mo ago
in my experience its been much worse than 1 px offset and the offsets are not consistent sometimes it renders something completely wrong also the xaml it generates is garbage also if youre only using it as a preview why not just use hot reload
br4kejet
br4kejet14mo ago
I guess i've just been lucky then... never had problems with it until VS2022 with that 1 pixel offset like in this image; that blue selection outline shouldn't overlap the checkbox's rectangle
No description
br4kejet
br4kejet14mo ago
I use hot reload though when I wanna play around with the style of actual live data which the designer can't really do, but the designer is still handy for getting an initial UI layout, and then I can go into the XAML and fix it up if nesessary i wouldn't enjoy using WPF as much if there was no designer because of things like the Grid gizmos I mentioned where clicking anywhere on those lines generates about 30 seconds of code instantly
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server