| 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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 
 |  
    /// <summary>
    /// Control d'edition
    /// </summary>
 
    public class EditorControl : Control
    {
        private const string EditContentControlName = "EditContentControl";
        private ContentControl EditContentControl = null;
 
        private const string VisualizeContentControlName = "VisualizeContentControl";
        private ContentControl VisualizeContentControl = null;
 
        /// <summary>
        /// Constructeur
        /// </summary>
 
        public EditorControl()
        {
            this.DefaultStyleKey = typeof(EditorControl);
        }
 
        /// <summary>
        /// Mode
        /// </summary>
 
        public enum EditorModes
        {
            Visualization,
            Editor
        }
 
        /// <summary>
        /// On applique le template
        /// </summary>
 
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
 
            this.EditContentControl = this.GetTemplateChild(EditContentControlName) as ContentControl;
            this.VisualizeContentControl = this.GetTemplateChild(VisualizeContentControlName) as ContentControl;
 
            // on réapplique si il y a eu modification avant que le template ait été appelé
            this.EditorModeChange(this.EditorMode);
        }
 
        /// <summary>
        /// Editor Mode
        /// </summary>
 
        public EditorModes EditorMode
        {
            get { return (EditorModes)GetValue(EditorModeProperty); }
            set { SetValue(EditorModeProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for EditorMode.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty EditorModeProperty =
            DependencyProperty.Register("EditorMode", typeof(EditorModes), typeof(EditorControl), new PropertyMetadata(EditorModes.Visualization));
 
        /// <summary>
        /// Changement de l'editeur
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
 
        protected static void OnEditorModeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            EditorControl editorControl = sender as EditorControl;
            // on applique le changement
            editorControl.EditorModeChange((EditorModes)e.NewValue);
        }
 
        /// <summary>
        /// Contenu de l'edition
        /// </summary>
 
        public object EditContent
        {
            get { return (object)GetValue(EditContentProperty); }
            set { SetValue(EditContentProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for EditContent.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty EditContentProperty =
            DependencyProperty.Register("EditContent", typeof(object), typeof(EditorControl), null);
 
 
        /// <summary>
        /// Contenu de visualisation
        /// </summary>
 
        public object VisualizeContent
        {
            get { return (object)GetValue(VisualizeContentProperty); }
            set { SetValue(VisualizeContentProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for VisualizeContent.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty VisualizeContentProperty =
            DependencyProperty.Register("VisualizeContent", typeof(object), typeof(EditorControl), null );
 
 
 
 
 
        /// <summary>
        /// Changement de l'editor Mode
        /// </summary>
        /// <param name="editorMode"></param>
 
        private void EditorModeChange(EditorModes editorMode)
        {
            // on change ici la visibilité
            if( this.EditContentControl == null || this.VisualizeContentControl == null ) return;
 
            switch (editorMode)
            {
                case EditorModes.Editor :
 
                    this.EditContentControl.Visibility = Visibility.Visible;
                    this.VisualizeContentControl.Visibility = Visibility.Collapsed;
 
                    break;
 
                case EditorModes.Visualization:
 
                    this.EditContentControl.Visibility = Visibility.Collapsed;
                    this.VisualizeContentControl.Visibility = Visibility.Visible;
 
                    break;
            }
        }
    } | 
Partager