Bonjour,

le titre du message est un peu vaste, mais mon problème survient lorsque j'utilise un template sur un combobox.
toutes les opérations de binding, notamment de selectedvalue sur mon combobox depuis une dependencyproperty fonctionne plutôt bien.

seulement j'ai beau mettre une validationrule sur le binding du selected value la méthode de validation n'est appellée qu'au moment ou j'update ma source depuis le code source GetBindinExpression(toto).UpdateSource().

j'ai beau changer la valeur de la propriété UpdateSourceTrigger de mon binding, rien y fait.

mon hypothèse: je ne sais pas faire un controltemplate sur une combobox.

XAML correspondant
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
 
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="comboboxTemplate">
    <WrapPanel>
        <ComboBox x:Name="internalCbx" 
                  ItemsSource="{TemplateBinding Property=ItemsSource}"
                  DisplayMemberPath="{TemplateBinding Property=DisplayMemberPath}"
                  SelectedValuePath="{TemplateBinding Property=SelectedValuePath}"
                  SelectedValue="{TemplateBinding Property=SelectedValue}"
                  IsEnabled="{TemplateBinding Property=IsEnabled}"
                  SelectedIndex="{TemplateBinding Property=SelectedIndex}"
                  Width="{TemplateBinding Property=Width}">
        </ComboBox>
        <TextBlock Margin="5,5,5,5"  x:Name="_warning" FontWeight="Bold"  Foreground="Red" Visibility="Collapsed" VerticalAlignment="Center" >
            !                        
            <TextBlock.ToolTip>Warning</TextBlock.ToolTip>
        </TextBlock>
    </WrapPanel>
    <ControlTemplate.Triggers>                    
        <DataTrigger Binding="{Binding ElementName=internalCbx, Path=SelectedItem.Key}" Value="MyKeyForWarning">
           <Setter TargetName="_warning" Property="Visibility" Value="Visible" />
        </DataTrigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

CODE BEHIND
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
// dans l'évènement loaded
var bindingValue = new Binding
{
    Path = new PropertyPath("Value"),
    Source = MyDependencyPropertySource,
    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
 
bindingValue.ValidationRules.Add(new MyValidationRule());
this._cbx.SetBinding(ComboBox.SelectedValueProperty, bindingValue);
Mes remarques:
- définition d'un combobox dans mon template de combobox (humour...)
- repaluchage des propriétés avec l'objet templatebinding
- c'est crade

J'ai bien regardé du côte de ItemsPresenter mais ça ne reprend pas du tout le template de base du combobox
Merci de me dire comment templatisé une combobox en reprenant les éléments du template par défaut de celui ci

merci