Results 1 to 6 of 6

Thread: WPF control names

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2016
    Posts
    216

    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!

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    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)

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: WPF control names

    I haven't had this problem with VS2010.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2016
    Posts
    216

    Re: WPF control names

    Quote Originally Posted by jmcilhinney View Post
    I wonder whether they decided to default to no names later
    They must have (VS2019 here).

    Quote Originally Posted by jmcilhinney View Post
    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?

    Quote Originally Posted by jmcilhinney View Post
    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?..

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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
  •  



Click Here to Expand Forum to Full Width