2

Hey Everyone, I am trying to get a better understanding of DependencyProperties in WPF. One thing I am trying to get clarity with is the LocalValue. There is a function called ReadLocalValue that is supposedly supposed to return the local value of the property otherwise it should return UnsetValue.

For instance I have a TextBlock named "justATest" with the TextProperty value set to "Test" on the element.

When I try calling:

MsgBox(ReadLocalValue(CType(justATest.TextProperty, DependencyProperty)).ToString)

All that gets returned is {DependencyProperty.UnsetValue}

Shouldn't I be getting back the value "Test"?

Can anyone shed some more light on the Local value and how the ReadLocalValue function works. Also are their any good resources out there that explain this?

Thanks, Nick U

H.B.
  • 166,899
  • 29
  • 327
  • 400
Nick U
  • 233
  • 1
  • 2
  • 13

1 Answers1

1

Shouldn't you be calling

justATest.ReadLocalValue(TextBox.TextProperty)
H.B.
  • 166,899
  • 29
  • 327
  • 400
  • I actually got it working with: justATest.ReadLocalValue(TextBlock.TextProperty) Thanks! – Nick U Apr 18 '11 at 05:31
  • Glad to hear that, i was worried that i might have misunderstood your code since i've never written any VB; sorry about getting the method name wrong there, got that mixed up a bit with `GetValue` :) – H.B. Apr 18 '11 at 05:38
  • For other readers, ReadLocalValue is giving me UnsetValue in one case, perhaps because the element is in a template (being set by a setter). [BaseValueSource](https://stackoverflow.com/a/809480/316760) tells me the value is not considered local even though it's set directly on the element in XAML. Yeesh. – Vimes Mar 17 '20 at 00:32