I created a window with a TextBlock inside. I bound the Text property and everything works fine. BUT when I change a restricted property inside a task, nothing works !!
Do you know why?
Public Async Sub StartProgress() Try LoadingText = "text 1" 'Works perfect Dim fResult As Boolean = Await LoadModules() If Not fResult Then MessageBox.Show(Me.Error) End If m_oView.Close() Catch ex As Exception Msg_Err(ex) End Try End Sub Public Async Function LoadModules() As Task(Of Boolean) Try Await Task.Delay(3000) LoadingText = "text 2" 'Nothing Happens Await Task.Delay(5000) LoadingText = "complete" 'Nothing Happens Await Task.Delay(3000) Return True Catch ex As Exception Me.Error = ex.Message Return False End Try End Function
text 2 and 3 are never displayed. If I dynamically change textblcok text (for example: m_oView.txtLoadingText.Text), it works fine (but this is not a solution)
EDIT This is a ViewModel base, each ViewModel implements this class.
Public Class VM_Base Implements IDisposable Implements INotifyPropertyChanged Private m_oDS As MxDataSet Public Property [Error] As String Public Event PropertyChanged As PropertyChangedEventHandler _ Implements INotifyPropertyChanged.PropertyChanged Protected Sub New() m_oDS = New MxDataSet End Sub Protected Overrides Sub Finalize() Try Me.Dispose(False) Debug.Fail("Dispose not called on ViewModel class.") Finally MyBase.Finalize() End Try End Sub Public Sub Dispose() Implements IDisposable.Dispose Me.Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overridable Sub Dispose(disposing As Boolean) End Sub Protected Overridable Sub OnPropertyChanged(propertyName As String) Me.EnsureProperty(propertyName) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName)) End Sub <Conditional("DEBUG")> _ Private Sub EnsureProperty(propertyName As String) If TypeDescriptor.GetProperties(Me)(propertyName) Is Nothing Then Throw New ArgumentException("Property does not exist.", "propertyName") End If End Sub End Class
How StartProgress is called:
<i:Interaction.Triggers> <i:EventTrigger EventName="ContentRendered"> <i:InvokeCommandAction Command="{Binding DataContext.WindowsActivatedCommand,ElementName=fLoading}" /> </i:EventTrigger> </i:Interaction.Triggers>
EDIT Binding a TextBlock to a Property
Public Property LoadingText As String Get Return m_sLoadingText End Get Set(value As String) m_sLoadingText = value OnPropertyChanged("LoadingText") End Set End Property
<TextBlock x:Name="txtLoading" Width="450" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding LoadingText}"> </TextBlock>
source share