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 8465497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:03:58+00:00 2026-06-10T15:03:58+00:00

Ok, i think i’m missing something here. Lets say, in a Winforms application i

  • 0

Ok, i think i’m missing something here.

Lets say, in a Winforms application i have a Form and a UserControl. I then add a Button to the UserCntrol, and then add the UserControl to the Form. Now the Button is added to the UserControl as a private member and until the UserControl exposes it’s private member through public property, the Form shouldn’t have access to the Button.

private void Form1_Load(object sender, EventArgs e)
{
    this.testUserControl1.
}

You won’t find the UserControl’s Button from the Form’s code. From the encapsulation point of view, i think this is exactly what we want.

Now lets say, i’m doing the same thing in a WPF application with a Window and a UserControl. I add a Button to the UserControl through Xaml and then add the UserControl to the Window. But now i can have access to the Button from the Window’s code.

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    this.testUserControl1.button1.Content = "What the HELL!";
}  

If i add the Button through code instead of Xaml, i still have the chance to make it private. But “building the UI declaratively, NOT through the code” – isn’t that’s why Xaml is there? Then isn’t it breaking the concept of Encapsulation?

EDIT : I know most of us, including myself, use MVVM to develop WPF applications where you don’t need to refer to your UI elements from your code-behind. But the context of the question still holds, right? I often build re-usable UserContolr (not as a View as in MVVM) to use them through out several Views as visual element, where i most often than not need to use the code-behind of the UserControl.

  • 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-06-10T15:04:00+00:00Added an answer on June 10, 2026 at 3:04 pm

    I’m not really sure what you’re saying. You can make the Button in XAML and have it be private as well:

    <Button x:FieldModifier="private" x:Name="Whatever" Content="This is a button" />
    

    You don’t have to do it through code. Just it defaults to (I think) internal rather than private. But like H.B. said, I rarely name my controls anyway, so I haven’t run into this myself.

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

Sidebar

Related Questions

I think I'm missing something basic here. Why is the third IF condition true?
Think at this scenario: I have a c# windows form application. This application was
I think I'm missing something basic here. Any explanation or pointers to previously asked
Think about the classic installation process, where you have a next button and when
I think I have a fairly basic question here. I'm not trying to waste
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want
I think I have a basic understanding of this, but am hoping that someone
I think this could be a very easy question for you. But I have
I think I have found a bug when setting or getting the Me.Top property
I think firefox's support to box model in CSS3 is soooooooooooooo poor... I have

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.