-
Aug 14th, 2020, 10:46 PM
#1
Thread Starter
Addicted Member
WPF control names
How do i get VS to assign default names to new controls (like it does for WinForms)?.. everything i make is nameless.. and it's a PITA. I don't want to waste time giving things names til i'm sure i know i'm keeping them.. but i do want to be able to create events for them.. and nameless controls can't be assigned to events!
-
Aug 15th, 2020, 01:42 AM
#2
Re: WPF control names
as far as I know, in WPF you have to set everything by yourself. nothing is automated.
regards
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 16th, 2020, 11:43 PM
#3
Re: WPF control names
I haven't had this problem with VS2010.
-
Aug 16th, 2020, 11:47 PM
#4
Re: WPF control names
I wonder whether they decided to default to no names later on because, if you're using WPF "properly", you won't be using events so you won't need names. Many people tend to use WPF in the same way as they used WinForms but that's a big waste of much of what WPF can do. You really ought to be implementing the MVVM pattern, in which you would react to changes in your View Model rather than in your View.
-
Aug 17th, 2020, 11:26 AM
#5
Thread Starter
Addicted Member
Re: WPF control names
Originally Posted by jmcilhinney
I wonder whether they decided to default to no names later
They must have (VS2019 here).
Originally Posted by jmcilhinney
you won't be using events so you won't need names
But you still need names to be able to access a given control's properties at runtime?
Originally Posted by jmcilhinney
You really ought to be implementing the MVVM pattern, in which you would react to changes in your View Model rather than in your View.
you lost me there.. had to google that stuff. I think you are expecting people to use the xml code rather than the form view?..
-
Aug 17th, 2020, 12:17 PM
#6
Re: WPF control names
If you're using WPF then you should read up on the MVVM (Model-View-ViewModel) design pattern. It's basically the WPF-specific version of MVP or MVC.
You don't need to access events or properties of your UI elements. You bind your ViewModel to your View in XAML and then all the action takes place in the ViewModel. You set the ViewModel properties in code and that data flows to the View via data-binding. The user does their thing in the UI and the changes they make flow back to the ViewModel via data-binding.
For instance, if you have a TextBox then you never have to refer to its Text property because you refer only to the ViewModel property that is bound to it and you don't have to handle the TextChanged event because you react to the changes in the ViewModel. Basically, if you're doing something that requires a control name then you're almost certainly doing it wrong.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|