| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 
 | public partial class Form : ChildWindow
{
    public Form()
    {
        InitializeComponent();
        DataContext = this;
    }
 
    private void OKButton_Click(object sender, RoutedEventArgs e)
    {
        if (Current is IEditableObject)
        {
            (Current as IEditableObject).EndEdit();
        }
        Current = null;
        this.DialogResult = true;
    }
 
    private void CancelButton_Click(object sender, RoutedEventArgs e)
    {
        if (Current is IEditableObject)
        {
            (Current as IEditableObject).CancelEdit();
            (Current as IEditableObject).EndEdit();
        }
        Current = null;
        this.DialogResult = false;
    }
 
    public DataTemplate DataTemplate
    {
        get { return (DataTemplate)GetValue(DataTemplateProperty); }
        set { SetValue(DataTemplateProperty, value); }
    }
 
    public static readonly DependencyProperty DataTemplateProperty =
        DependencyProperty.Register("DataTemplate", typeof(DataTemplate), typeof(Form), new PropertyMetadata(null));
 
    public object Current
    {
        get { return (object)GetValue(CurrentProperty); }
        set { SetValue(CurrentProperty, value); }
    }
 
    public static readonly DependencyProperty CurrentProperty =
        DependencyProperty.Register("Current", typeof(object), typeof(Form), new PropertyMetadata(null, new PropertyChangedCallback(CurrentChanged)));
 
 
    private static void CurrentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
    {
        if (args.NewValue is IEditableObject)
        {
            (args.NewValue as IEditableObject).BeginEdit();
        }
 
        if (args.OldValue is IEditableObject)
        {
            (args.OldValue as IEditableObject).EndEdit();
        }
    }
 
    public ObservableCollection<Category> Categories
    {
        get { return (ObservableCollection<Category>)GetValue(CategoriesProperty); }
        set { SetValue(CategoriesProperty, value); }
    }
 
    // Using a DependencyProperty as the backing store for Categories.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty CategoriesProperty =
        DependencyProperty.Register("Categories", typeof(ObservableCollection<Category>), typeof(Form), new PropertyMetadata(null));
} | 
Partager