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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:59:33+00:00 2026-05-29T14:59:33+00:00

This has been bugging me for a while, so I asked a coworker if

  • 0

This has been bugging me for a while, so I asked a coworker if he could make any sense of it, and now I’m here 😉

How come you can access private members of the holding class in the PropertyChangedCallback of a dependency property?
Let me explain further what i mean through this example:

 /// <summary>
    /// Interaction logic for ZeControl.xaml
    /// </summary>
    public partial class ZeControl : UserControl
    {
        public ZeControl()
        {
            InitializeComponent();
        }

        private bool m_Trololo; //Please note that this field is PRIVATE!

        #region Text
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(ZeControl), new UIPropertyMetadata(
                new PropertyChangedCallback((dpo, dpce) =>
                    {
                        ((ZeControl)dpo).m_Trololo = true; //How the hell?
                        //this.m_Trololo <-- would not compile, the callback is static.
                    })));
        #endregion
    }

Isn’t this breaking encapsulation? how does it even compiles?

I’m asking this mainly because I make use of it in my WPF applications: it allows me to keep a variable private while still accessing it in callbacks.
But since it really doesn’t feel right at all, I wouldn’t want this to be “fixed” in WPF vNext, making my apps incompatible.

Best regards,

bab.

  • 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-29T14:59:34+00:00Added an answer on May 29, 2026 at 2:59 pm

    The callback is defined in the same class that owns the private member, nothing wrong with that kind of access. It might seem odd that a private instance member is seemingly accessed “from the outside” but you are still in the same class.

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

Sidebar

Related Questions

This one has been bugging me for a while now. Is there a way
This Jquery problem has been bugging me for a while now. I developed a
This one has been bugging me for a while now, but I never seem
Ok, this has been bugging me for a while now. And I wonder how
This question has been bugging me for a while now. When writing a CSS
This has been bugging me for a long time now and I can't seem
This is a question that has been bugging me for a while. I started
This has been bugging me for more than two days now, so i thought
This question has been bugging me for a while. I am looking for a
This problem has been bugging me for a while. I have to load a

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.