J'ai une zone de texte et un bouton. La commande de bouton doit modifier la propriété qui est liée au contrôle TextBox.Problème de liaison MVVM simple
Mais je ne vois aucun changement visuel après l'exécution de la commande. Je pense qu'il question facile lié à WPF contraignant
S'il vous plaît aidez-moi cette question
Source de l'application:
<UserControl.DataContext>
<local:SampleViewModel />
</UserControl.DataContext>
<Grid>
<StackPanel>
<TextBox Height="23" Width="120" Text="{Binding MyName}" />
<Button Content="Click" Command="{Binding ButtonCommand}" />
</StackPanel>
</Grid>
ViewModel:
Private _myName As String
Public Property MyName As String
Get
Return _myName
End Get
Set(value As String)
_myName = value
OnPropertyChanged("MyName")
End Set
End Property
Public _buttonCommand As DelegateCommand
Public ReadOnly Property ButtonCommand As DelegateCommand
Get
Return If(_buttonCommand IsNot Nothing, _buttonCommand,
New DelegateCommand(AddressOf Execute, AddressOf CanExecute))
End Get
End Property
Private Sub Execute()
MyName = "Executed"
End Sub
Private Function CanExecute() As Boolean
Return True
End Function
Public Event PropertyChanged As PropertyChangedEventHandler
Private Sub OnPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Avez-vous essayé de mettre un point d'arrêt dans Execute()? – Blachshma
pourriez-vous essayer de définir un point d'arrêt à 'Execute' et voir si elle est exécutée du tout? – Vlad
Mon nom ne doit-il pas être observable? – IronMan84