IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

Trouver les DependencyProperty d'un control


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 4
    Par défaut Trouver les DependencyProperty d'un control
    Bonjour vous tous...

    J’espère être au bon endroit pour poser ce type de question :

    Voilà je cherche à énumérer les DependencyProperty de n’import quel DependencyObject via une methode ex :

    Public List< DependencyProperty> GetDependencyPropertys(DependencyObject element)
    {
    // ??
    }

    ou
    Public List< DependencyProperty> GetDependencyPropertys(Type element)
    {
    // ??
    }

    Une idée ??

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    2 210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 210
    Par défaut
    Salut,

    Voici un post qui en parle :
    http://social.msdn.microsoft.com/For...-3e3ba118c89c/

    Il en arrive à la fonction suivante (j'ai pas testé) :
    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
        public IList<DependencyProperty> GetAttachedProperties(DependencyObject obj) {
          List<DependencyProperty> attached = new List<DependencyProperty>();
     
          foreach (System.ComponentModel.PropertyDescriptor pd in System.ComponentModel.TypeDescriptor.GetProperties(obj,
              new Attribute[] { new System.ComponentModel.PropertyFilterAttribute(System.ComponentModel.PropertyFilterOptions.All) })) {
            System.ComponentModel.DependencyPropertyDescriptor dpd =
                System.ComponentModel.DependencyPropertyDescriptor.FromProperty(pd);
     
            if (dpd != null && dpd.IsAttached) {
              attached.Add(dpd.DependencyProperty);
            }
          }
     
          return attached;
        }

  3. #3
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Par défaut
    Sinon, avec la reflection, tu devrais y arriver mais cette solution semble plus optimisée

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 4
    Par défaut Merci
    public abstract class BigThanks<T> where T :

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2009
    Messages : 4
    Par défaut Petit détail...
    L'obectif du départ étant de pouvoir lister les DependencyProperty pour un DependencyObject donné.
    De ce fait, nous ne souhaitons pas de propriété jointe (dpd.IsAttached =false)...

    if (pd.ComponentType == ComponentType)
    {
    if (dpd != null && !dpd.IsAttached)
    {
    DependencyPropertysResult.Add(dpd.DependencyProperty);
    }
    }


    Voilà mon petit code pour RoutedEvent et DependencyProperty:
    Les methodes avec "All" retourn également les DependencyProperty ou RoutedEvent des classes parentes. Sinon uniquement les elemenents de la classe elle même.


    Code : 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
    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
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
          public class DependencyObjectDescriptor
            {
                public static List<DependencyProperty> GetDependencyProperty(DependencyObject DependencyObject)
                {
                    //using System.ComponentModel;
                    //using System.Window;
                    //using System.Collections.Generic;
                    if (DependencyObject == null)
                        return null;
                    List<DependencyProperty> DependencyPropertysResult = new List<DependencyProperty>();
                    Type ComponentType = DependencyObject.GetType();
                    PropertyDescriptorCollection PropertyDescriptors = TypeDescriptor.GetProperties(DependencyObject);
     
                    foreach (PropertyDescriptor pd in PropertyDescriptors)
                    {
     
                        DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(pd);
                        if (pd.ComponentType == ComponentType)
                        {
                            if (dpd != null && !dpd.IsAttached)
                            {
                                DependencyPropertysResult.Add(dpd.DependencyProperty);
                            }
     
                        }
                    }
     
                    return DependencyPropertysResult;
                }
                public static List<DependencyProperty> GetDependencyProperty(Type DependencyObjectType)
                {
                    //using System.ComponentModel;
                    //using System.Window;
                    //using System.Collections.Generic;
                    if (DependencyObjectType == null)
                        return null;
                    List<DependencyProperty> DependencyPropertysResult = new List<DependencyProperty>();
                    Type ComponentType = DependencyObjectType;
                    PropertyDescriptorCollection PropertyDescriptors = TypeDescriptor.GetProperties(DependencyObjectType);
     
                    foreach (PropertyDescriptor pd in PropertyDescriptors)
                    {
     
                        DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(pd);
                        if (pd.ComponentType == ComponentType)
                        {
                            if (dpd != null && !dpd.IsAttached)
                            {
                                DependencyPropertysResult.Add(dpd.DependencyProperty);
                            }
     
                        }
                    }
     
                    return DependencyPropertysResult;
                }
                public static List<DependencyProperty> GetAllDependencyProperty(DependencyObject DependencyObject)
                {
                    //using System.ComponentModel;
                    //using System.Window;
                    //using System.Collections.Generic;
                    if (DependencyObject == null)
                        return null;
                    List<DependencyProperty> DependencyPropertysResult = new List<DependencyProperty>();
                    PropertyDescriptorCollection PropertyDescriptors = TypeDescriptor.GetProperties(DependencyObject);
                    foreach (PropertyDescriptor pd in PropertyDescriptors)
                    {
     
                        DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(pd);
     
                        if (dpd != null && !dpd.IsAttached)
                        {
                            DependencyPropertysResult.Add(dpd.DependencyProperty);
                        }
     
                    }
     
                    return DependencyPropertysResult;
                }
                public static List<DependencyProperty> GetAllDependencyProperty(Type DependencyObjectType)
                {
                    //using System.ComponentModel;
                    //using System.Window;
                    //using System.Collections.Generic;
                    if (DependencyObjectType == null)
                        return null;
                    List<DependencyProperty> DependencyPropertysResult = new List<DependencyProperty>();
                    PropertyDescriptorCollection PropertyDescriptors = TypeDescriptor.GetProperties(DependencyObjectType);
                    foreach (PropertyDescriptor pd in PropertyDescriptors)
                    {
     
                        DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(pd);
     
                        if (dpd != null && !dpd.IsAttached)
                        {
                            DependencyPropertysResult.Add(dpd.DependencyProperty);
                        }
     
                    }
     
                    return DependencyPropertysResult;
                }
     
                public static List<RoutedEvent> GetRoutedEvent(DependencyObject DependencyObject)
                {
                    //using System.Window;
                    //using System.Collections.Generic;
                    if (DependencyObject == null)
                        return null;
                    List<RoutedEvent> RoutedEventsResult = new List<RoutedEvent>();
                    try
                    {
                        RoutedEventsResult = EventManager.GetRoutedEventsForOwner(DependencyObject.GetType()).ToList();
                    }
                    catch { }//ArgumentNullException 
     
     
                    return RoutedEventsResult;
                }
                public static List<RoutedEvent> GetRoutedEvent(Type DependencyObjectType)
                {
                    //using System.Window;
                    //using System.Collections.Generic;
                    if (DependencyObjectType == null)
                        return null;
                    List<RoutedEvent> RoutedEventsResult = new List<RoutedEvent>();
                    try
                    {
                        RoutedEventsResult = EventManager.GetRoutedEventsForOwner(DependencyObjectType).ToList();
                    }
                    catch { }//ArgumentNullException 
     
     
                    return RoutedEventsResult;
                }
                public static List<RoutedEvent> GetAllRoutedEvent(DependencyObject DependencyObject)
                {
                    //using System.Window;
                    //using System.Collections.Generic;
                    if (DependencyObject == null)
                        return null;
                    List<Type> AllTypeparent = new List<Type>();
                    Type tmptype = DependencyObject.GetType();
                    AllTypeparent.Add(tmptype);
                    while (tmptype.BaseType != null)
                    {
                        AllTypeparent.Add(tmptype.BaseType);
                        tmptype = tmptype.BaseType;
                    }
                    List<RoutedEvent> RoutedEventsResult = new List<RoutedEvent>();
     
                    foreach (var TypeItem in AllTypeparent)
                    {
                        try
                        {
                            RoutedEventsResult.AddRange(EventManager.GetRoutedEventsForOwner(TypeItem).ToList());
                        }
                        catch { }//ArgumentNullException 
                    }
     
                    return RoutedEventsResult;
                }
                public static List<RoutedEvent> GetAllRoutedEvent(Type DependencyObjectType)
                {
                    //using System.Window;
                    //using System.Collections.Generic;
                    if (DependencyObjectType == null)
                        return null;
                    List<Type> AllTypeparent = new List<Type>();
                    Type tmptype = DependencyObjectType;
                    AllTypeparent.Add(DependencyObjectType);
                    while (tmptype.BaseType != null)
                    {
                        AllTypeparent.Add(tmptype.BaseType);
                        tmptype = tmptype.BaseType;
                    }
                    List<RoutedEvent> RoutedEventsResult = new List<RoutedEvent>();
     
                    foreach (var TypeItem in AllTypeparent)
                    {
                        try
                        {
                            RoutedEventsResult.AddRange(EventManager.GetRoutedEventsForOwner(TypeItem).ToList());
                        }
                        catch { }//ArgumentNullException 
                    }
     
                    return RoutedEventsResult;
                }
            }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. trouver les hotes
    Par tanky dans le forum C++Builder
    Réponses: 14
    Dernier message: 08/05/2007, 13h17
  2. [langage] Trouver les fichiers sans la case
    Par nledez dans le forum Langage
    Réponses: 2
    Dernier message: 22/12/2004, 12h07
  3. Trouver les redirections dans des traces
    Par severine dans le forum Développement
    Réponses: 3
    Dernier message: 21/04/2004, 18h51
  4. [GUI] Ou trouver les standard ?
    Par Braim dans le forum Windows
    Réponses: 5
    Dernier message: 01/10/2003, 08h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo