我有一个班级,其中有一个DependencyProperty成员:
public class SomeClass : FrameworkElement
{
public static readonly DependencyProperty SomeValueProperty
= DependencyProperty.Register(
"SomeValue",
typeof(int),
typeof(SomeClass));
new PropertyMetadata(
new PropertyChangedCallback(OnSomeValuePropertyChanged)));
public int SomeValue
{
get { return (int)GetValue(SomeValueProperty); }
set { SetValue(SomeValueProperty, value); }
}
public int GetSomeValue()
{
// This is just a contrived example.
// this.SomeValue always returns the default value for some reason,
// not the current binding source value
return this.SomeValue;
}
private static void OnSomeValuePropertyChanged(
DependencyObject target, DependencyPropertyChangedEventArgs e)
{
// This …Run Code Online (Sandbox Code Playgroud)