小编Emm*_*sis的帖子

绑定和异步操作

我在里面创建了一个带有TextBlock的Window.我绑定了Text属性,一切正常. 但是 当我在任务内部更改有界属性时,没有任何作用!

你知道为什么吗?

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
Run Code Online (Sandbox Code Playgroud)

文本2和3从未显示过.如果我动态更改textblcok的文本(例如:m_oView.txtLoadingText.Text)它工作正常(但它不是一个解决方案) …

wpf binding asynchronous mvvm .net-4.5

6
推荐指数
1
解决办法
3145
查看次数

标签 统计

.net-4.5 ×1

asynchronous ×1

binding ×1

mvvm ×1

wpf ×1