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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:39:10+00:00 2026-05-29T18:39:10+00:00

In my .NET 4.0 project I’ve got an object that has public fields and

  • 0

In my .NET 4.0 project I’ve got an object that has public fields and this object neither implements INotifyPropertyChanged nor inherits DependencyObject, and it will never do. However, I need a mechanism to “bind” to fields of this object in my WPF control. I know I can’t do it directly as binding requires a dependency property (or at least, properties and notifying property changes), so what can I do to implement the binding functionality I need. I’ve tried something like this in my WPF control:

    void FirePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public float Friction
    {
        get
        {
            if (CurrentObject != null)
            {
                return CurrentObject.Friction;
            }
            else
            {
                return 0.0f;
            }
        }
        set
        {
            if (CurrentObject != null)
            {
                CurrentObject.Friction = value;
                FirePropertyChanged("Friction");
            }
        }
    }

    public PlatformObjectTemplate CurrentObject
    {
        get
        {
            return GetValue(CurrentObjectProperty) as PlatformObjectTemplate;
        }
        set
        {
            SetValue(CurrentObjectProperty, value);
            FirePropertyChanged("Friction");
            FirePropertyChanged("CurrentObject");
            BindShapes();
            IntersectionComboBox.SelectedItem = CurrentObject.IntersectionStaticMethod;
        }
    }

    public static readonly DependencyProperty CurrentObjectProperty = DependencyProperty.Register("CurrentObject", typeof(PlatformObjectTemplate), typeof(PlatformStaticObjectPropertyEditor), new PropertyMetadata(null));

My WPF control implements INotifyPropertyChanged, and my PlatformObjectTemplate does not have properties, just public fields like Friction. I need to bind to my object in XAML as such:

(in my control): //DoubleUpDown is from the WPF toolkit.

<tk:DoubleUpDown Margin="91,10,7,0" Name="doubleUpDown1" VerticalAlignment="Top" Value="{Binding Friction, ElementName=window, FallbackValue=0}" />

(in my main window):

<my:PlatformStaticObjectPropertyEditor x:Name="platformStaticObjectPropertyEditor1" CurrentObject="{Binding CurrentObject, ElementName=window}" />

I put a breakpoint in the getter of Friction property, and it tries to bind before the CurrentObject is bound, and because it is null, I can’t read the correct friction value from the object. I’ve tried to fire Friction property changed in the setter of the CurrentObject, to populate the Friction when CurrentObject gets set, but that doesn’t work either.

Ok, here are two requirements:

PlatformObjectTemplate will not use properties. It will have public fields.
I need a declarative way of binding as usual, just as I used in the XAML above.

I probably have got things over-complicated, and I must be missing some stuff. What is the most “correct” and “declarative” way of doing this right, within the constraints of my requirements just above?

Thanks,
Can.

  • 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-29T18:39:12+00:00Added an answer on May 29, 2026 at 6:39 pm

    object neither implements INotifyPropertyChanged nor inherits DependencyObject, and it will never. However, I need a mechanism to "bind" to fields of this object in my WPF control

    poyra, I have this same situation. Because one cannot bind to instance fields, your best option is to create wrapper classes which implement INotifyPropertyChanged.

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

Sidebar

Related Questions

I have a .net project that has a web reference to a service. I
I have asp.net project which has got GridViews, Buttons, Navigators etc... I have 10-15
After upgrading Fax.NET project to .NET 4 Client Profile i got this Exception: MissingMethodException:
I have a .net project (MySolution.Common) that uses the app.config. I am using the
I have a .NET project which references another assembly that is built outside of
The ASP.NET project I am working on has 3 layers; UI, BLL, and DAL.
I have a .NET project that's always been built/run by/on 32 bit machines. I
I have a .Net project called: Whatever.Web.UI: I use this project to put all
I have an ASP.NET project that uses XML Serialization for the main operation for
I have an ASP.net project which involves using a custom IHttpModule. This module will

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.