Bonjour,
je rencontre un petit problème sur mon appli Silverlight. La situation est assez simple:
Une page avec un grille chargant une liste d'Entity (System.ServiceModel.DomainServices.Entity)
3 boutons (les classiques Création, Edition, Suppression) dont les 2 premiers ouvrent une ChildWindow
Mon problème est le suivant: comment désactiver le bouton "Valider" des child windows si les conditions ne sont pas présentes?
Pour le moment j'ai quelques chose dans ce genre:
XAML
ViewModel
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <TextBox Height="23" HorizontalAlignment="Left" Name="txtNomFonction" Text="{Binding ActiveFonction.Fonction_Libelle, Mode=TwoWay}"> <i:Interaction.Triggers> <i:EventTrigger EventName="TextChanged"> <cmd:EventToCommand Command="{Binding CanSaveFonctionCommand,Mode=OneWay}" /> </i:EventTrigger> </i:Interaction.Triggers> </TextBox> <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" IsEnabled="{Binding EditButtonsEnabled}" Width="75" Height="23" /> <Button x:Name="CancelButton" Content="Annuler" Click="CancelButton_Click" Width="75" Height="23" />
Le problème est que lorsque CanSaveFonctionCommand est déclanché par l'Event TextChanged, la propriété de l'objet (ActiveFonction.Fonction_Libelle) n'est pas encore mise à jour lorsqu'on atteint le code de la méthode CanSaveFonction().
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 public class GererFonctionViewModel : ViewModel { public GererFonctionViewModel(IEventAggregator messageBus) { this.messageBus = messageBus; CanSaveFonctionCommand = new DelegateCommand<object>(CheckCanSaveFonction); } public ICommand CanSaveFonctionCommand { get; private set; } private Boolean editButtonsEnabled; public Boolean EditButtonsEnabled { get { return editButtonsEnabled; } set { editButtonsEnabled = value; OnPropertyChanged("EditButtonsEnabled"); } } public void CheckCanSaveFonction(object obj) { EditButtonsEnabled = CanSaveFonction(); } private bool CanSaveFonction() { return ActiveFonction != null && !string.IsNullOrEmpty(ActiveFonction.Fonction_Libelle); } }
D'où ma question: Comment puis-je faire pour Activé/désactiver ce bouton OK en fonction du résultat de la méthode CheckCanSaveFonction()?
Partager