In MainWindow class I have defined DependencyProperty MyDepObjProperty (MyDepObj is int type).
In another class file ClassA.cs under the same namespace I want to read the above MyDepObj value.
ClassA is instantiated multiple times and at multiple places, without having to change that code, how can I read within this file the value of variable from MainWindow.xaml.cs?
namespace WpfApp { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public static readonly DependencyProperty MyDepObjProperty = DependencyProperty.Register("MyDepObj", typeof(int), typeof(MainWindow)); public int MyDepObj { get { return (int)GetValue(MyDepObjProperty); } set { SetValue(MyDepObjProperty, value); } } } }
namespace WpfApp { class ClassA { public void DoSomething() { MainWindow.MyDepObj ???; } } }
Thanks,
-srinivas y.
sri