Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 870431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:28:28+00:00 2026-05-15T10:28:28+00:00

If you need to access a WPF control from the code behind, you need

  • 0

If you need to access a WPF control from the code behind, you need to supply a Name attribute to it in XAML.

In many cases, you don’t need to access controls from the code behind, since a lot of coding logic such as binding is better applied directly inside XAML.

My question is: Is there a performance gain from not supplying the name attribute to controls? Or is it a good habit to give names to all controls on the page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:28:29+00:00Added an answer on May 15, 2026 at 10:28 am

    Yes there is definitely a performance gain from not supplying “name” attributes.

    WPF’s “Name” mechanism can be useful, but it uses extra RAM and CPU in several ways:

    1. The XAML compiler allocates an extra slot in your class for every named object (4 bytes each)
    2. The XAML compiler adds code to your class to initate each of these
    3. The BAML processor calls back your code to initialize the name in each case
    4. The BAML processor also adds the name to a dictionary, requiring an additional 20+ bytes per name
    5. When looking up names you really need you may run into dictionary collisions with names you don’t really need

    For a simple control, adding a Name to control can increase the cost of using that control by 5% or so. That’s not a lot, but why waste your CPU cycles and your RAM on names that are unnecessary?

    Bottom line: If you don’t need Names on your objects, don’t name them. Usually the content or binding of a control is plenty to identify a control’s purpose. And if that isn’t enough documentation, you can always use XML comments, which are free.

    I’d have to say it is a very bad habit to name all your controls, not just because of the cost but also because it encourages you to refer to your controls by name rather than using proper view model and binding techniques. Most of my XAML doesn’t use “Name” for any controls, let alone all of them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 446k
  • Answers 446k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assuming you only have 123 or 124 in myid: mydf$result… May 15, 2026 at 7:22 pm
  • Editorial Team
    Editorial Team added an answer Unloaded is fired when the control is removed from the… May 15, 2026 at 7:22 pm
  • Editorial Team
    Editorial Team added an answer Your page is rendering in Quirks Mode on IE8. When… May 15, 2026 at 7:22 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.