Bonjour,
Je souhaiterai savoir s'il existe un moyen pour pouvoir définir une DependencyProperty ou autre afin que l'on puisse modifier la méthode appelée lors d'un clic sur un UserControl, comme c'est faisable pour les boutons et autres éléments de base.
Ceci dans l'optique de pouvoir créer un UserControl correspondant à un bouton amélioré. Je poste le code de mon contrôle :
L'objectif est de remplacer la ligne
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 <UserControl x:Class="Maquette1553.Utils.LabeledButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="labeledButton"> <UserControl.Resources> <DropShadowBitmapEffect x:Key="shadowEffect" ShadowDepth="{Binding ElementName=labeledButton, Path=ShadowDepth}" Direction="{Binding ElementName=labeledButton, Path=ShadowDirection}" Color="{Binding ElementName=labeledButton, Path=ShadowColor}" Opacity="{Binding ElementName=labeledButton, Path=ShadowOpacity}" Softness="{Binding ElementName=labeledButton, Path=ShadowSoftness}" /> </UserControl.Resources> <Button x:Name="btn" Width="95" Click="btnClick"> <Border BorderThickness="0"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> <Image x:Name="imgBtn" Source="{Binding ElementName=labeledButton, Path=Source}" Width="{Binding ElementName=labeledButton, Path=Width}" /> <StackPanel VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5"> <TextBlock x:Name="text" Text="{Binding ElementName=labeledButton, Path=Text}" FontWeight="Bold" Foreground="{Binding ElementName=labeledButton, Path=TextColor}" BitmapEffect="{StaticResource shadowEffect}" FontSize="{Binding ElementName=labeledButton, Path=FontSize}" HorizontalAlignment="Center" /> </StackPanel> </Grid> </Border> </Button> </UserControl>
par quelque chose du style
Code : Sélectionner tout - Visualiser dans une fenêtre à part Click="btnClick"
avec la méthode dont le nom est stocké dans la propriété Click qui sera définie dans la fenêtre contenant mon UserControl.
Code : Sélectionner tout - Visualiser dans une fenêtre à part Click="{StaticResource Click}"
Merci d'avance.
Partager