Ramon bihon
Ramon bihon

Reputation: 475

wpf: How does Dependency Property Communicate with each other

How does Dependency Property Communicate with each other.

I have two dependency property in a single class

public bool SaveToStream
        {
            get { return (bool)GetValue(SaveToStreamProperty); }
            set { SetValue(SaveToStreamProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SaveToStream.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SaveToStreamProperty =
            DependencyProperty.Register("SaveToStream", typeof(bool), typeof(PdfViewerControlHelper), new PropertyMetadata(OnSaveToStreamChanged));

        private static void OnSaveToStreamChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {

            //how to i populate the contents of the ExtractedData here.
        }


        public ObservableCollection<DataItem> ExtractedData
        {
            get { return (ObservableCollection<DataItem>)GetValue(ExtractedDataProperty); }
            set { SetValue(ExtractedDataProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ExtractedData.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ExtractedDataProperty =
            DependencyProperty.Register("ExtractedData", typeof(ObservableCollection<DataItem>), typeof(PdfViewerControlHelper),
                new FrameworkPropertyMetadata(new ObservableCollection<DataItem>(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, null));

I have two dependency property. SaveToStream which is a boolean, and ExtractedData which is an observable collection.

What i want is if a changes is made in the SaveToStream is changed. I want to populate in the ExtractedData collection. But in my OnSaveToStreamChanged method. I can't access the ExtractedData collection. How do i solve this? Thank you.

Upvotes: 0

Views: 64

Answers (1)

Clemens
Clemens

Reputation: 128061

The first argument passed to the PropertyChangedCallback is the control instance:

private static void OnSaveToStreamChanged(
    DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var control = (PdfViewerControlHelper)d;

    // do something with control.ExtractedData
}

Upvotes: 2

Related Questions