Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Read MainWindow Dependency Property value from a class file

$
0
0

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


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>