Bonjour,

J'aimerai créer une classe qui dérive de UserControl afin de fournir :
1) des propriétés supplémentaires
2) des méthodes totalement implémentées
3) des méthodes à redéfinir par les classes filles de mon nouveau composant.

Pour cela, j'ai créé une classe abstraite fournissant tout ce qui est nécessaire :
Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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
 
using System.ComponentModel;
using System.Windows.Controls;
using ihm1553.Worker;
using System.Windows.Input;
 
namespace Utils.Controls
{
    public abstract class DisposableUserControl : UserControl, INotifyPropertyChanged
    {
        #region Class members
        /// <summary>
        /// The worker object that do the treatment.
        /// </summary>
        protected AbstractWorker workerObject_m;
        /// <summary>
        /// Is there a running treatment?
        /// </summary>
        private bool isRunning_m;
 
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion Class members
 
        #region Properties
        /// <summary>
        /// Is there a running treatment?
        /// </summary>
        public bool IsRunning
        {
            get { return isRunning_m; }
            protected set
            {
                isRunning_m = value;
                RaisePropertyChanged("IsRunning");
            }
        }
        #endregion Properties
 
        #region Methods that have to be implemented by children classes
        /// <summary>
        /// This method should be used to verify that no treatment is running 
        /// in the UserControl:
        ///     - if treatments are running, then user should be prompted to terminate them.
        ///     - if no treatments are running, then the UserControl should be disposed.
        /// </summary>
        /// <returns>True if disposal has been approuved, false otherwise.</returns>
        public abstract bool dispose();
        /// <summary>
        /// This method is used to dispose all members of the UserControl
        /// </summary>
        protected abstract void doDispose();
        #endregion Methods that have to be implemented by children classes
 
        #region Methods
        /// <summary>
        /// Method that updates the cursor render in order to match the 
        /// status of the treatment.
        /// This method has to be called on the Loaded event of each
        /// children UserControl.
        /// </summary>
        protected void displayCursor()
        {
            //Display a "busy" cursor if the scan is running.
            if (IsRunning)
            {
                Mouse.OverrideCursor = Cursors.AppStarting;
            }
            else
            {
                Mouse.OverrideCursor = null;
            }
        }
        #endregion Methods
 
        #region INotifyPropertyChanged methods
        /// <summary>
        /// Raise an event when a property is changed.
        /// </summary>
        /// <param name="propertyName">The name of the property that has been changed.</param>
        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion INotifyPropertyChanged methods
    }
}

Ensuite, les contrôles que je crée dérivent de cette classe abstraite :
Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
public partial class ScanControl : DisposableUserControl
...
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
<ctrl:DisposableUserControl  x:Class="MyNameSpace.ScanControl"
                              xmlns:ctrl="clr-namespace:Utils.Controls">
</ctrl:DisposableUserControl>

Or comme ma classe DisposableUserControl est déclarée abstraite, l'aperçu de Visual Studio me dit qu'il ne peut pas créer d'instance de cette classe et du coup ne peut pas m'afficher d'aperçu de mon IHM.

Quelqu'un voit-il un moyen de coupler le comportement que je souhaite obtenir (UserControl enrichi + méthodes abstraites) avec l'aperçu sous VS ?
(et j'aimerai autant que possible ne pas avoir à créer un UserControl contenant les propriétés et méthodes pleinement implémentées + une interface avec les méthodes à implémenter)

Merci d'avance.