This project has moved. For the latest updates, please go here.

How to Implement the PropertyChangedEvent for the SelectedPersianDate Property

Dec 7, 2011 at 7:23 AM


i see in your code that you have used INotifyPropertyChange Interface with the SelectedPersianDate Property
But I Can't Use the Event,  I want to write a code in the EventHandler to do something when the selectedPersianDate Changes
 but i don't see the event, Can someone help me with this plz?

Dec 7, 2011 at 8:11 AM
Edited Dec 7, 2011 at 8:12 AM

SelectedPersianDate is defined as a DependencyProperty here. So you can easily listen to its changes. Something like:

Silverlight Version:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace SilverlightPersianDatePickerUsage
    public partial class NormalTest
        public NormalTest()
            this.Loaded += NormalTest_Loaded;
            RegisterForNotification(this.PDatePicker1, "SelectedPersianDate",
                (d, e) =>
                    //Do something ...

        public void RegisterForNotification(FrameworkElement element, string propertyName, PropertyChangedCallback callback)
            Binding b = new Binding(propertyName) { Source = element };
            var prop = DependencyProperty.RegisterAttached(
                "ListenAttached" + propertyName,
                new PropertyMetadata(callback));
            element.SetBinding(prop, b);

        void NormalTest_Loaded(object sender, RoutedEventArgs e)
            PDatePicker1.SelectedDate = DateTime.Now.ToString();
            PDatePicker2.SelectedPersianDate = "1390/03/10";

WPF version: