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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:57:29+00:00 2026-05-30T11:57:29+00:00

Was just wondering about DependencyProperties. Usually I’m seeing this kind of coding standard when

  • 0

Was just wondering about DependencyProperties.

Usually I’m seeing this kind of coding standard when executing some code after a DependencyProperty has changed.

public int SomeProperty
    {
        get { return (int)GetValue(SomePropertyProperty); }
        set { SetValue(SomePropertyProperty, value); }
    }

    public static readonly DependencyProperty SomePropertyProperty =
        DependencyProperty.Register("SomeProperty", typeof(int), typeof(MainWindow), new UIPropertyMetadata(new DependencyPropertyChangedEventHandler(OnSomePropertyChanged)));

    private static void OnSomePropertyChanged(object obj, DependencyPropertyChangedEventArgs e)
    {
        //Some logic in here
    }

But I don’t think I’ve never seen this kind of implementation –

public int SomeProperty
    {
        get { return (int)GetValue(SomePropertyProperty); }
        set 
        { 
            SetValue(SomePropertyProperty, value);

            //Execute code in here
        }
    }

    public static readonly DependencyProperty SomePropertyProperty =
        DependencyProperty.Register("SomeProperty", typeof(int), typeof(MainWindow), new UIPropertyMetadata(0));

Is this considered a bad practice?

Thanks!

  • 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-30T11:57:31+00:00Added an answer on May 30, 2026 at 11:57 am

    This isn’t just bad practice, this will actually result in incorrect behavior. When binding to dependency properties in XAML, the SetValue method will be called directly, not the setter. Basically, you can’t guarantee that code there will even be executed.

    Source: http://www.switchonthecode.com/tutorials/wpf-tutorial-introduction-to-dependency-properties

    A little bit of a side note here – don’t ever put anything but the
    GetValue and SetValue calls inside the property wrapper. This is
    because you never know if someone will set the property through the
    wrapper, or straight through a SetValue call – so you don’t want to
    put any extra logic in the property wrapper. For example, when you set
    the value of a dependency property in XAML, it will not use the
    property wrapper – it will hit the SetValue call directly, bypassing
    anything that you happened to put in the property wrapper.

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

Sidebar

Related Questions

Just wondering about this code below... when I turn off my internet connection and
Just wondering about some practice about this; I have made a simple visual C#
Just wondering about this... I have several separate javascript files, that all contain code
Hey, I just started wondering about this as I came upon a code that
I was just wondering about some CodeWarning (ConstructorsShouldNotCallBaseClassVirtualMethods), and if there is a better
I'm just wondering about this one. I'm creating an ASP.NET webform containing lots of
ok... so I feel really stupid asking this question.. but just wondering about the
Just wondering about this one : Whats the difference, or is there a difference
Just wondering the best way to go about this, I am building a VB.NET
I just wondering about this.It is said that .NET is better than MFC in

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.