Я хочу изменить значение текстового поля, но этот код не работает. Я вижу только последнее значение. Если вы хотите помочь мне скопировать и вставить код. Большое спасибоMvvm. Текстовое поле никогда не изменяется с помощью System.Threading.Thread.Sleep
Это XAML
<TextBox HorizontalAlignment="Left" Height="46"
Margin="4,4,4,4" VerticalAlignment="Top" Width="162"
Text="{Binding Path=Msg,
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Это VB кода.
Imports System.Threading
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System
Class MainWindow
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
Dim x As New Abc
Me.DataContext = x
End Sub
End Class
Public Class Abc
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub OnPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Protected Sub OnNotifyPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Private Property _Msg As String
Public Property Msg As String
Get
Return _Msg
End Get
Set(value As String)
_Msg = value
OnPropertyChanged("Msg")
End Set
End Property
Private m_ButtonCommand As ICommand
Public Property ButtonCommand() As ICommand
Get
Return m_ButtonCommand
End Get
Set(value As ICommand)
m_ButtonCommand = value
End Set
End Property
Public Sub displayMessage(ByVal param As Object)
Msg = "How"
System.Threading.Thread.Sleep(1000)
Msg = "Are"
System.Threading.Thread.Sleep(1000)
Msg = "you"
System.Threading.Thread.Sleep(1000)
Msg = "?"
System.Threading.Thread.Sleep(1000)
End Sub
Private Function CandisplayMessage(ByVal param As Object) As Boolean
Return True
End Function
Public Sub New()
m_ButtonCommand = New DelegateCommand(AddressOf displayMessage, AddressOf CandisplayMessage)
End Sub
End Class
Public Class DelegateCommand
Implements ICommand
Private m_canExecute As Func(Of Object, Boolean)
Private m_executeAction As Action(Of Object)
Private m_canExecuteCache As Boolean
Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements ICommand.CanExecuteChanged
Public Sub New(ByVal executeAction As Action(Of Object), ByVal canExecute As Func(Of Object, Boolean))
Me.m_executeAction = executeAction
Me.m_canExecute = canExecute
End Sub
Public Function CanExecute(ByVal parameter As Object) As Boolean Implements ICommand.CanExecute
Dim temp As Boolean = m_canExecute(parameter)
If m_canExecuteCache <> temp Then
m_canExecuteCache = temp
RaiseEvent CanExecuteChanged(Me, New EventArgs())
End If
Return m_canExecuteCache
End Function
Public Sub Execute(ByVal parameter As Object) Implements ICommand.Execute
m_executeAction(parameter)
End Sub
End Class
........................................... ..
Ты спишь нить UI. Как поток UI должен обновлять UI ***, когда вы сказали ему заснуть? *** – Will