我需要图像源绑定版本背后的代码

时间:2019-01-10 22:45:09

标签: xaml

后面的代码。

Class MainWindow 

Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

    Dim myBinding As New Binding
    With myBinding
        .Source = Image1.Source
        .Mode = BindingMode.Default
        .UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
    End With
End Sub

End Class   

那么,为什么 myBinding 在后面的代码中不起作用?

1 个答案:

答案 0 :(得分:0)

为了在其源属性发生更改时更新绑定,您需要指定一个路径:

Dim myBinding As New Binding
With myBinding
    .Source = Image1
    .Path = new PropertyPath("Source")
End With

除此之外,设置BindingMode.DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged是没有意义的。对此绑定没有影响。