Hello everyone, I encountered such a problem
I have a window with resources
DataContext="{Binding RelativeSource={RelativeSource Self}}"> <Window.Resources> <my:MyClass x:Key="Key" MyProperty="{Binding Path=MyProp1}" MyProp2="{Binding Path=MyProp2}"/> </Window.Resources>
All properties are propdp properties.
public class MyClass: FrameworkElement { public int MyProperty { get { return (int)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(int), typeof(MyClass), new UIPropertyMetadata(0)); public int MyProp2 { get { return (int)GetValue(MyProp2Property); } set { SetValue(MyProp2Property, value); } } // Using a DependencyProperty as the backing store for MyProp2. This enables animation, styling, binding, etc... public static readonly DependencyProperty MyProp2Property = DependencyProperty.Register("MyProp2", typeof(int), typeof(MainWindow), new UIPropertyMetadata(0)); }
Why does data binding not work?