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 :

Boîtes de dialogue + ValidationRule => bonne pratique


Sujet :

Windows Presentation Foundation

  1. #1
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut Boîtes de dialogue + ValidationRule => bonne pratique
    Bonjour,

    J'ai créé une boîte de dialogue générique qui permet juste de saisir une valeur, et à laquelle j'ai rajouté une DependencyProperty afin de pouvoir spécifier le label qui va être afficher devant le champs de saisie de la valeur.

    Ce que j'aimerai c'est pouvoir effectuer un contrôle de validité sur la valeur saisie (via une ValidationRule de préférence).

    Mon problème est que plutôt que de devoir redéfinir une nouvelle classe pour chaque type de données à saisir (int, string, entier positifs, entiers compris entre x1 et x2, etc...), j'aimerai pouvoir réutiliser ma boîte de dialogue et passer ma ValidationRule à la création de celle-ci.
    Mais je ne vois pas trop comment faire.

    Quelqu'un verrait-il une solution ?
    Merci d'avance !

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

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    J'ai pas compris: tu veux faire une ValidationRule générique ?

  3. #3
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    J'ai pas compris: tu veux faire une ValidationRule générique ?
    Non en fait, ce que j'aimerai c'est avoir une boîte de dialogue générique, à laquelle je pourrai passer une ValidationRule avec un truc du genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    InputDialog dialog_l = new InputDialog();
    PositiveIntValidationRule rule_l = new PositiveIntValidationRule();
    //NegativeIntValidationRule rule_l = new NegativeIntValidationRule();
    //MyValidationRule rule_l = new MyValidationRule(lowerLimit, upperLimit);
    dialog_l.setValidationRule(rule_l);
    Et que l'appel à la méthode setValidationRule affecte ma ValidationRule au champ texte de saisie de ma boîte de dialogue.

  4. #4
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par seiryujay Voir le message
    que l'appel à la méthode setValidationRule affecte ma ValidationRule au champ texte de saisie de ma boîte de dialogue.
    Si j'ai moi aussi bien compris tu veux savoir quel est le code à mettre dans le corps de la méthode setValidationRule() pour que celle-ci affecte la Collection ValidationRules de l'objet Binding de ton TextBox.

    Alors tu dois récupérer l'objet Binding de ton TextBox et à la collection ValidationRules du Binding tu ajoutes ton custom Validation Rule.

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

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Citation Envoyé par h2s84 Voir le message
    Alors tu dois récupérer l'objet Binding de ton TextBox et à la collection ValidationRules du Binding tu ajoutes ton custom Validation Rule.
    Effectivement, cela semble correspondre mieux à son besoin.

    Petit conseil en passant: Plutot que de passer par une méthode setValidationRule, utilise une DependencyProperty, au niveau de ta classe InputDialog et dans la callback de notifications de changement, tu affectes la règle de validation

  6. #6
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    utilise une DependencyProperty, au niveau de ta classe InputDialog et dans la callback de notifications de changement, tu affectes la règle de validation
    ça c'est de la bonne pratique

  7. #7
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    Citation Envoyé par h2s84 Voir le message
    Alors tu dois récupérer l'objet Binding de ton TextBox et à la collection ValidationRules du Binding tu ajoutes ton custom Validation Rule.
    Justement, comment puis-je faire ça ?


    Citation Envoyé par Thomas Lebrun
    Petit conseil en passant: Plutot que de passer par une méthode setValidationRule, utilise une DependencyProperty, au niveau de ta classe InputDialog et dans la callback de notifications de changement, tu affectes la règle de validation
    Euh, j'ai l'impression que la callback de notification de changement doit être une méthode static (d'après les exemples que j'ai vu).
    Du coup, je ne peux pas accéder à l'objet txtValue correspondant au champs texte de ma boîte de dialogue.
    Du coup, je fais quoi ? J'affecte ma ValidationRule à ma TextBox dans le setter de ma DependencyProperty ?

  8. #8
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    Citation Envoyé par seiryujay
    Euh, j'ai l'impression que la callback de notification de changement doit être une méthode static (d'après les exemples que j'ai vu).
    Du coup, je ne peux pas accéder à l'objet txtValue correspondant au champs texte de ma boîte de dialogue.
    Du coup, je fais quoi ? J'affecte ma ValidationRule à ma TextBox dans le setter de ma DependencyProperty ?
    Au temps pour moi, on peut accéder au contrôle grâce au paramètre source...

    Par contre, je ne sais toujours pas comment attacher ma ValidationRule à ma TextBox.

  9. #9
    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
    Points : 3 015
    Points
    3 015
    Par défaut
    Salut,

    Lorsque la ValidationRule changera, il faudra faire quelque chose comme ça :

    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
          Binding bd = new Binding();
          bd.Source = ...;
          bd.Path = ...;
          ...
          bd.ValidationRules.Add(e.NewValue as ValidationRule);
          textbox.SetBinding(TextBox.TextProperty, bd);

    La textBox est accessible comme tu as pu le voir. Après j'ai pas testé, mais c'est comme ça qu'on associe une ValidationRule.

  10. #10
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    Ben justement, j'ai essayé de faire ça :
    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
     
            private static void onValidationRuleChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
            {
                InputDialog dialog_l = source as InputDialog;
                ValidationRule rule_l = e.NewValue as ValidationRule;
     
                Binding myBinding_l = new Binding();
                myBinding_l.Path = new PropertyPath("Value");
                myBinding_l.Mode = BindingMode.TwoWay;
                myBinding_l.ValidatesOnDataErrors = true;
                myBinding_l.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                myBinding_l.ValidationRules.Add(rule_l);
     
                dialog_l.txtValue.SetBinding(InputDialog.DialogValidationRuleProperty, myBinding_l);
            }
    Mais ça marche pas... (je ne passe pas dans la méthode Validate() de ma ValidationRule)

    Alors que quand je fais ça, ça marche bien :
    Code xml : 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
     
                    <TextBox x:Name="txtValue"
                             Width="50"
                             Validation.ErrorTemplate="{StaticResource validationTemplate}"
                             Style="{StaticResource textBoxInError}">
                        <TextBox.Text>
                            <Binding ElementName="inputDialog"
                                     Path="Value"
                                     Mode="TwoWay"
                                     UpdateSourceTrigger="PropertyChanged"
                                     ValidatesOnDataErrors="True">
                                <Binding.ValidationRules>
                                    <val:PositiveIntegerValidationRule_C />
                                </Binding.ValidationRules>
                            </Binding>
                        </TextBox.Text>
                    </TextBox>

    PS : y'a pas moyen de récupérer le Binding en cours et d'y rajouter ma ValidationRule ? Parce que sinon faut que je redéfinisse tout en C# alors que certains trucs sont déjà fait dans mon XAML...

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

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Citation Envoyé par h2s84 Voir le message
    ça c'est de la bonne pratique
    Quitte à coder, autant le faire bien

  12. #12
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par seiryujay Voir le message
    PS : y'a pas moyen de récupérer le Binding en cours et d'y rajouter ma ValidationRule ?
    Je crois tu dois récupérer quelque chose du genre BindingExpression de ton textbox. Si je ne me trompe je croix que cela doit se trouver dans mon livre de référence en WPF qui est WPF par la pratique du grand Thomas LEBRUN. Mais il y a ça pour l'instant.
    Dernière modification par Invité ; 25/03/2009 à 15h25.

  13. #13
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    Citation Envoyé par h2s84 Voir le message
    Je crois tu dois récupérer quelque chose du genre BindingExpression de ton textbox. Si je ne me trompe je croix que cela doit trouver mon livre référence en WPF qui est WPF par la pratique du grand Thomas LEBRUN. Mais il y a ça pour l'instant.
    Yes !
    Ca marche nickel avec ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    InputDialog dialog_l = source as InputDialog;
    ValidationRule rule_l = e.NewValue as ValidationRule;
     
    Binding myBinding_l = BindingOperations.GetBinding(dialog_l.txtValue, TextBox.TextProperty);
    myBinding_l.ValidationRules.Add(rule_l);
    Merci bien !
    Je vais tester le résultat final avec plusieurs ValidationRule histoire d'être bien sûr, mais ça marche impec avec celle que j'avais créée...

  14. #14
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par seiryujay Voir le message
    Merci bien !
    à WPF par la pratique.
    N'oublie pas un petit résolu.

  15. #15
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    Bon ben testé et validé !
    Merci pour le coup de main.

    Voici le code final de ma boîte de dialogue de saisie de données "générique" :

    1) Le XAML de ma boîte de dialogue :
    Code xml : 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
     
    <Window x:Class="Utils.Dialogs.InputDialog"
            x:Name="inputDialog"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:val="clr-namespace:Utils.ValidationRules"
            Title="{Binding ElementName=inputDialog, Path=Title}"
            Icon="pack://application:,,,/Images/16x16/edit.png"
            FontSize="12"
            Background="Transparent"
            SizeToContent="WidthAndHeight"
            ResizeMode="NoResize"
            WindowStyle="None"
            AllowsTransparency="True"
            ShowInTaskbar="False"
            WindowStartupLocation="CenterOwner"
            FocusManager.FocusedElement="{Binding ElementName=txtValue}">
     
        <Window.Resources>
            <!-- Template used to display a picture after the textbox in order to warn for error messages -->
            <ControlTemplate x:Key="validationTemplate">
                <DockPanel>
                    <AdornedElementPlaceholder />
                    <Image Source="pack://application:,,,/Images/16x16/flag.png"
                           Width="16"
                           Height="16"
                           Margin="3,0,0,0"/>
                </DockPanel>
            </ControlTemplate>
     
            <!-- Style used to display error messages in a tooltip -->
            <Style x:Key="textBoxInError"
                   TargetType="{x:Type TextBox}">
                <Style.Triggers>
                    <Trigger Property="Validation.HasError"
                             Value="true">
                        <Setter Property="ToolTip"
                                Value="{Binding ElementName=txtValue, Path=(Validation.Errors).CurrentItem}" />
                        <Setter Property="ToolTip.IsOpen"
                                Value="True" />
                        <Setter Property="ToolTip.StaysOpen"
                                Value="True" />
                        <Setter Property="BitmapEffect">
                            <Setter.Value>
                                <OuterGlowBitmapEffect GlowColor="Red"
                                                       GlowSize="2" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Window.Resources>
     
        <Border CornerRadius="12,12,12,12"
                BorderBrush="#FF020202"
                BorderThickness="0,0,0,0"
                Height="Auto">
            <Border.Background>
                <LinearGradientBrush StartPoint="0,0"
                                     EndPoint="1,1">
                    <GradientStop Color="LightSteelBlue"
                                  Offset="0.0" />
                    <GradientStop Color="White"
                                  Offset="0.5" />
                    <GradientStop Color="LightSteelBlue"
                                  Offset="1.0" />
                </LinearGradientBrush>
            </Border.Background>
     
            <StackPanel Orientation="Vertical">
                <!-- Input part -->
                <StackPanel Orientation="Horizontal"
                            HorizontalAlignment="Center"
                            Margin="30,15,30,0">
                    <Label Content="{Binding ElementName=inputDialog, Path=DialogLabel}"
                           Margin="0,0,5,0" />
                    <TextBox x:Name="txtValue"
                             Width="50"
                             Validation.ErrorTemplate="{StaticResource validationTemplate}"
                             Style="{StaticResource textBoxInError}">
                        <TextBox.Text>
                            <Binding ElementName="inputDialog"
                                     Path="Value"
                                     Mode="TwoWay"
                                     UpdateSourceTrigger="PropertyChanged"
                                     ValidatesOnDataErrors="True">
                            </Binding>
                        </TextBox.Text>
                    </TextBox>
                </StackPanel>
     
                <!-- Buttons part -->
                <StackPanel Orientation="Horizontal"
                            HorizontalAlignment="Center"
                            Margin="30,15,30,15">
                    <Button x:Name="btnOk"
                            Content="OK"
                            Width="70"
                            Height="25"
                            Margin="0,0,5,0"
                            IsDefault="True"
                            Click="btnOkClick" />
                    <Button x:Name="btnCancel"
                            Content="Cancel"
                            Width="70"
                            Height="25"
                            Margin="5,0,0,0"
                            IsCancel="True"
                            Click="btnCancelClick" />
                </StackPanel>
            </StackPanel>
        </Border>
    </Window>

    2) Le code source de ma boîte de dialogue :
    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
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
     
    using System.Windows;
    using System.Windows.Input;
    using System;
    using System.Windows.Controls;
    using System.ComponentModel;
    using System.Windows.Data;
     
    namespace Utils.Dialogs
    {
        /// <summary>
        /// Logique d'interaction pour InputDialog.xaml
        /// </summary>
        public partial class InputDialog : Window, INotifyPropertyChanged
        {
            #region Dependency properties
     
            public static DependencyProperty DialogLabelProperty = DependencyProperty.Register(
               "DialogLabel", typeof(string), typeof(InputDialog));
     
            public static DependencyProperty DialogValidationRuleProperty = DependencyProperty.Register(
               "DialogValidationRule", typeof(ValidationRule), typeof(InputDialog), new FrameworkPropertyMetadata(onValidationRuleChanged));
     
            #endregion
     
     
     
     
            #region Class members
     
            /// <summary>
            /// The value returned by the dialog.
            /// </summary>
            private object value_m;
            /// <summary>
            /// The validation rule used on the textbox.
            /// </summary>
            private ValidationRule validationRule_l;
     
            public event PropertyChangedEventHandler PropertyChanged;
     
            #endregion
     
     
     
     
            #region Constructors
     
            /// <summary>
            /// 
            /// </summary>
            /// <param name="value_p"></param>
            public InputDialog(string title_p, string label_p)
            {
                InitializeComponent();
     
                Title = title_p;
                DialogLabel = label_p;
            }
     
            /// <summary>
            /// 
            /// </summary>
            /// <param name="value_p"></param>
            public InputDialog(string title_p, string label_p, object value_p)
            {
                InitializeComponent();
     
                Title = title_p;
                DialogLabel = label_p;
                Value = value_p;
            }
     
            /// <summary>
            /// 
            /// </summary>
            /// <param name="value_p"></param>
            public InputDialog(string title_p, string label_p, object value_p, ValidationRule rule_p)
            {
                InitializeComponent();
     
                Title = title_p;
                DialogLabel = label_p;
                Value = value_p;
                DialogValidationRule = rule_p;
            }
     
            #endregion
     
     
     
     
            #region Properties
     
            /// <summary>
            /// The label to display.
            /// </summary>
            public string DialogLabel
            {
                get { return (string)GetValue(DialogLabelProperty); }
                set
                {
                    // Valid reference?
                    if (value == null)
                    {
                        throw new Exception("Invalid label value (" + value + ")");
                    }
     
                    SetValue(DialogLabelProperty, value);
                }
            }
     
            /// <summary>
            /// The validation rule used on the textbox.
            /// </summary>
            public ValidationRule DialogValidationRule
            {
                get { return (ValidationRule)GetValue(DialogValidationRuleProperty); }
                set
                {
                    // Valid reference?
                    if (value == null)
                    {
                        throw new Exception("Invalid Validation rule (" + value + ")");
                    }
     
                    SetValue(DialogValidationRuleProperty, value);
                }
            }
     
            /// <summary>
            /// The value typed in.
            /// </summary>
            public object Value
            {
                get { return value_m; }
                set
                {
                    value_m = value;
                    RaisePropertyChanged("Value");
                }
            }
     
            #endregion
     
     
     
     
            #region Events management
     
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnOkClick(object sender, RoutedEventArgs e)
            {
                if (isValid(this))
                {
                    this.DialogResult = true;
                }
            }
     
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnCancelClick(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
            }
     
            /// <summary>
            /// Move window on dragging.
            /// </summary>
            /// <param name="e"></param>
            protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
            {
                base.OnMouseLeftButtonDown(e);
     
                this.DragMove();
            }
     
            #endregion
     
     
     
     
            #region Methods
     
            /// <summary>
            /// Validate all dependency objects in a window
            /// </summary>
            /// <param name="node"></param>
            /// <returns></returns>
            private bool isValid(DependencyObject node)
            {
                // Check if dependency object was passed
                if (node != null)
                {
                    // Check if dependency object is valid.
                    // NOTE: Validation.GetHasError works for controls that have validation rules attached 
                    bool isValid = !Validation.GetHasError(node);
                    if (!isValid)
                    {
                        // If the dependency object is invalid, and it can receive the focus,
                        // set the focus
                        if (node is IInputElement)
                        {
                            Keyboard.Focus((IInputElement)node);
                        }
                        return false;
                    }
                }
     
                // If this dependency object is valid, check all child dependency objects
                foreach (object subnode in LogicalTreeHelper.GetChildren(node))
                {
                    if (subnode is DependencyObject)
                    {
                        // If a child dependency object is invalid, return false immediately,
                        // otherwise keep checking
                        if (isValid((DependencyObject)subnode) == false)
                        {
                            return false;
                        }
                    }
                }
     
                // All dependency objects are valid
                return true;
            }
     
            /// <summary>
            /// Callback used on DialogValidationRuleProperty setting, in order to add it to the textbox.
            /// </summary>
            /// <param name="value"></param>
            /// <returns></returns>
            private static void onValidationRuleChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
            {
                InputDialog dialog_l = source as InputDialog;
                ValidationRule rule_l = e.NewValue as ValidationRule;
     
                Binding myBinding_l = BindingOperations.GetBinding(dialog_l.txtValue, TextBox.TextProperty);
                myBinding_l.ValidationRules.Add(rule_l);
            }
     
            #endregion
     
     
     
     
            #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>
            private void RaisePropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
     
            #endregion
        }
    }
    (en espérant que ce système soit le bon pour le but recherché)

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

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Citation Envoyé par h2s84 Voir le message
    Si je ne me trompe je croix que cela doit se trouver dans mon livre de référence en WPF qui est WPF par la pratique du grand Thomas LEBRUN.
    lol merci

  17. #17
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    C'est clair qu'on te fait une pub monstrueuse ici : entre ton bouquin et ton blog, on n'arrête pas de vanter tes mérites.
    Va falloir nous filer une commission sur tes prochaines ventes ^^

  18. #18
    Membre éclairé
    Avatar de seiryujay
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    950
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 950
    Points : 722
    Points
    722
    Par défaut
    Tant qu'on y est (et si les règles du forum l'autorisent), on peut aussi dire que chez Winwise ils font de très bonnes formations WPF
    (même si je n'ai pas eu l'occasion de rencontrer notre cher Rédacteur / Modérateur ^^)

  19. #19
    Invité
    Invité(e)
    Par défaut
    Ok, j'ai supprimé le dernier message. Vu que j'ai eu pas mal de problème avec un modérateur du site et je lui ai promis de respecter les règles.

    Alors thanks.

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

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Ok bon, je crois qu'on va arrêter là pour les compliments


    Mais merci quand même

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

Discussions similaires

  1. Bonnes pratiques de protections individuelles
    Par Community Management dans le forum Sécurité
    Réponses: 22
    Dernier message: 05/04/2013, 11h47
  2. [Kylix] Imprimer le contenu d'une boîte de dialogue
    Par cmp-france dans le forum EDI
    Réponses: 13
    Dernier message: 18/10/2003, 20h31
  3. Réponses: 3
    Dernier message: 29/08/2003, 10h57
  4. [MFC] Boîte de dialogue chronométrée
    Par mdriesbach dans le forum MFC
    Réponses: 5
    Dernier message: 18/02/2003, 12h40
  5. Dll et boîte de dialogue MFC
    Par paulj dans le forum MFC
    Réponses: 3
    Dernier message: 19/12/2002, 09h59

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