Bonjour,
J'aurais besoin d'un petit coup de main pour une action qui est en soi très simple.
J'ai une interface en xaml qui contient un combo box. Celui ci possède 2 options statiques (Société ou PersonnePhysique). A la suite de cela, j'ai un formulaire pour ajouter un client (un client étant soit une société, soit une personne physique). Une société est caractérisée par les mêmes données qu'une personne physique à une exception prêt : la société ne comporte pas de prénom. J'aimerais donc enlever le champs prénom de ma fenêtre si la personne choisi "société" dans ma combobox, et le remettre si elle change en "personne physique". J'aimerais également pouvoir influencer mon binding en fonction de cela (e.xxxx pour les personne physique et s.xxx pour les sociétés), mais si ce n'est pas possible je peux le faire dans le code sans trop de soucis.
J'ai cru comprendre qu'il était possible de faire un binding entre 2 éléments xaml directement. J'ai aussi cru comprendre qu'il était possible de faire cela au moyen d'un usercontrol, chose que j'aimerais éviter.
Voici mon xaml :
Et voici mon interface :
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 <Grid x:Name="AjouterClient" Margin="20"> <Grid.RowDefinitions> <RowDefinition Height="40"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="22"/> <RowDefinition Height="Auto" MinHeight="23"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="50" /> </Grid.ColumnDefinitions> <ComboBox x:Name="typeClient" Grid.Row="0" Grid.Column="1" Height="25" VerticalContentAlignment="Center"> <ComboBoxItem Content="Personne physique" IsSelected="True" /> <ComboBoxItem Content="Société" IsSelected="False" /> </ComboBox> <Label Grid.Row="1" Grid.Column="0" Content="Nom *"/> <Border BorderThickness="3" Grid.Row="1" Grid.Column="1"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=e.Nom}" /> </Border> <Label Grid.Row="1" Grid.Column="2" Content="Prenom *"/> <Border BorderThickness="3" Grid.Row="1" Grid.Column="3"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=e.Prenom}" /> </Border> <Label Grid.Row="2" Grid.Column="0" Content="Rue"/> <Border BorderThickness="3" Grid.Row="2" Grid.Column="1"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=a.Rue}" /> </Border> <Label Grid.Row="2" Grid.Column="2" Content="Numero"/> <Border BorderThickness="3" Grid.Row="2" Grid.Column="3"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=a.Numero}" /> </Border> <Label Grid.Row="3" Grid.Column="0" Content="Code postal"/> <Border BorderThickness="3" Grid.Row="3" Grid.Column="1"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=a.CodePostal}" /> </Border> <Label Grid.Row="3" Grid.Column="2" Content="Ville"/> <Border BorderThickness="3" Grid.Row="3" Grid.Column="3"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=a.Ville}" /> </Border> <Label Grid.Row="4" Grid.Column="0" Content="Pays"/> <Border BorderThickness="3" Grid.Row="4" Grid.Column="1"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=a.Pays}" /> </Border> <Label Grid.Row="4" Grid.Column="2" Content="Email"/> <Border BorderThickness="3" Grid.Row="4" Grid.Column="3"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=e.Email}" /> </Border> <Label Grid.Row="5" Grid.Column="0" Content="GSM"/> <Border BorderThickness="3" Grid.Row="5" Grid.Column="1"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=e.GSM}" /> </Border> <Label Grid.Row="5" Grid.Column="2" Content="Telephone"/> <Border BorderThickness="3" Grid.Row="5" Grid.Column="3"> <TextBox BorderBrush="Black" MaxHeight="30" Text="{Binding Path=e.Telephone}" /> </Border> <Button Content="Ajouter" Grid.Column="1" Grid.Row="8" Command="{Binding Employe.AddCommand, Source={StaticResource Locator}}" Click="Button_Click_1"/> <Button Content="Annuler" Grid.Column="3" Grid.Row="8" Click="Button_Click_2"/> </Grid>
Partager