Question

I'm seeing some strange behavior with my dependency properties. I set up the following property in my class MyControl.

public static DependencyProperty MyTempProperty =
    DependencyProperty.Register("MyTemp", typeof(double), typeof(MyControl),
                                new UIPropertyMetadata(0d, OnMyTempChanged));

private static void OnMyTempChanged(
    DependencyObject source, DependencyPropertyChangedEventArgs e)
{
    MyControl c = (MyControl)source;
    //do something here
}

public double MyTemp
{
    get { return (double)GetValue(MyTempProperty); }
    set { SetValue(MyTempProperty, value); }
}

Later on, I set the following:

MyTemp = 6.2831;

I set a breakpoint and I checked the address of "this". Then I set a breakpoint inside OnMyTempChanged (see above), and check the address of source. It's not the same as the address of "this" (MyControl) from earlier. Also, the data is not the same. Other properties that I have set are not the same either. It looks like I have two different instances of the MyControl object.

What's going on here? I need the data from the original object...not the messed up copy I get inside the PropertyChangedCallback.

Was it helpful?

Solution

Nit's comment got me on the right track. I have two copies of my control based on my layout design. I have a pinned and an unpinned version of my menu. They were not staying in sync with each other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top