Bonjour,

J'ai un template control LabeledCheckbox qui fonctionne très bien. Cependant, je voudrais en créer un nouveau sur base de clui-ci, mais avec 2 checkbox.

Mais je n'arrive pas à détecter l'event IsChecked sur chque checkbox séparément.

Est-ce que quelqu'un peut m'aider ?

Merci d'avance.

Voici le code xaml :

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
<!--labeled double checkbox-->
 
    <Style TargetType="{x:Type Controls:LabeledDoubleCheckBoxControl}">
        <Setter Property="Validation.ErrorTemplate" Value="{StaticResource LabeledValidationTemplate}"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Margin" Value="8,8,8,0"/>
        <Setter Property="Height" Value="24"/>
        <Setter Property="Width" Value="Auto"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="FontFamily" Value="Verdana"/>
        <Setter Property="FontSize" Value="9"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Foreground" Value="{StaticResource ControlForegroundBrush}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:LabeledDoubleCheckBoxControl}">
                    <Grid>
 
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20"/>
                            <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type CheckBox}}, Path=LabelWidth}"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type CheckBox}}, Path=LabelWidthCheckOne}"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type CheckBox}}, Path=LabelWidthCheckTwo}"/>
                        </Grid.ColumnDefinitions>
 
                        <TextBlock Grid.Column="0"
                                   x:Name="MandatoryIndicatorControl"
                                   VerticalAlignment="Center"
                                   Foreground="{StaticResource MandatoryIndicatorForegroundBrush}"
                                   Text="*"
                                   Visibility="Hidden"
                                   />
 
                        <TextBlock  Grid.Column="1"
                                    VerticalAlignment="Center"
                                    Foreground="{StaticResource LabelForegroundBrush}"
                                    Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type CheckBox}}, Path=LabelText}"
                                    />
 
                        <BulletDecorator  Grid.Column="2" Background="Transparent" VerticalAlignment="Center">
                            <BulletDecorator.Bullet>
                                <Border x:Name="BorderOne"
                                        Width="18"
                                        Height="18"
                                        CornerRadius="0"
                                        Background="{StaticResource ControlBackgroundBrush}"
                                        BorderThickness="1"
                                        BorderBrush="{StaticResource ControlBorderBrush}"
                                        >
 
                                    <Image x:Name="CheckMarkOne"
                                           Source="pack://application:,,,/FBL.Registre.Core.UI.Resources;component/Resources/coche.gif"
                                           Stretch="None"
                                           />
 
                                </Border>
                            </BulletDecorator.Bullet>
                        </BulletDecorator>
 
                        <TextBlock  Grid.Column="3"
                                    VerticalAlignment="Center"
                                    Foreground="{StaticResource LabelForegroundBrush}"
                                    Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type CheckBox}}, Path=LabelTextCheckOne}"
                                    Margin="20,0,0,0"
                                    />
 
                        <BulletDecorator  Grid.Column="4" Background="Transparent" VerticalAlignment="Center">
                            <BulletDecorator.Bullet>
                                <Border x:Name="BorderTwo"
                                        Width="18"
                                        Height="18"
                                        CornerRadius="0"
                                        Background="{StaticResource ControlBackgroundBrush}"
                                        BorderThickness="1"
                                        BorderBrush="{StaticResource ControlBorderBrush}"
                                        >
 
                                    <Image x:Name="CheckMarkTwo"
                                           Source="pack://application:,,,/FBL.Registre.Core.UI.Resources;component/Resources/coche.gif"
                                           Stretch="None"
                                           />
 
                                </Border>
                            </BulletDecorator.Bullet>
                        </BulletDecorator>
 
                        <TextBlock  Grid.Column="5"
                                    VerticalAlignment="Center"
                                    Foreground="{StaticResource LabelForegroundBrush}"
                                    Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type CheckBox}}, Path=LabelTextCheckTwo}"
                                    Margin="20,0,0,0"
                                    />
 
                    </Grid>
 
                    <ControlTemplate.Triggers>
 
                        <Trigger Property="IsChecked" SourceName="CheckMarkOne" Value="False">
                            <Setter TargetName="CheckMarkOne" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
 
                        <Trigger Property="IsChecked" SourceName="CheckMarkOne" Value="{x:Null}">
                            <Setter TargetName="CheckMarkOne" Property="Visibility" Value="Visible"/>
                        </Trigger>
 
                        <Trigger Property="IsMouseOver" SourceName="CheckMarkOne" Value="True">
                            <Setter TargetName="BorderOne" Property="Background"
                                    Value="{StaticResource ControlIsOverBackgroundBrush}" />
                        </Trigger>
 
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="BorderOne" Property="Background"
                                    Value="{StaticResource DisabledBackgroundBrush}" />
                            <Setter TargetName="BorderOne" Property="BorderBrush"
                                    Value="{StaticResource DisabledBorderBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                            <Setter TargetName="BorderTwo" Property="Background"
                                    Value="{StaticResource DisabledBackgroundBrush}" />
                            <Setter TargetName="BorderTwo" Property="BorderBrush"
                                    Value="{StaticResource DisabledBorderBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                        </Trigger>
 
                        <Trigger Property="IsChecked" SourceName="CheckMarkTwo" Value="False">
                            <Setter TargetName="CheckMarkTwo" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
 
                        <Trigger Property="IsChecked" SourceName="CheckMarkTwo" Value="{x:Null}">
                            <Setter TargetName="CheckMarkTwo" Property="Visibility" Value="Visible"/>
                        </Trigger>
 
                        <Trigger Property="IsMouseOver" SourceName="CheckMarkTwo" Value="True">
                            <Setter TargetName="BorderTwo" Property="Background"
                                    Value="{StaticResource ControlIsOverBackgroundBrush}" />
                        </Trigger>
 
                        <Trigger Property="Validation.HasError" Value="True">
                            <Setter Property="ToolTip"
                                    Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors)[0].ErrorContent}"/>
                        </Trigger>
 
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMandatory}"
                                     Value="True">
                            <Setter TargetName="MandatoryIndicatorControl" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
 
                    </ControlTemplate.Triggers>
 
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>