Binding WPF约束问题

Binding WPF约束问题,binding,Binding,我有一个奇怪的问题 我正在尝试绑定到图像对象。我可以完美地绑定渲染转换。但OpacityProperty将无法正确绑定。我没有得到错误,但不透明度不会更新或更改,而TranslationTransform会。我不知道为什么: Dim alpha As New Double alpha = 0 Dim vImage As Image = CreatevImageControl() Dim translation As New TranslateTransform(0, 0) myGrid.Ch

我有一个奇怪的问题

我正在尝试绑定到图像对象。我可以完美地绑定渲染转换。但OpacityProperty将无法正确绑定。我没有得到错误,但不透明度不会更新或更改,而TranslationTransform会。我不知道为什么:

Dim alpha As New Double
alpha = 0

Dim vImage As Image = CreatevImageControl()
Dim translation As New TranslateTransform(0, 0)

myGrid.Children.Add(vImage)
Dim binding1 As New Binding()
binding1.Source = translation
vImage.SetBinding(Image.RenderTransformProperty, binding1)

Dim binding2 As New Binding()
binding2.Source = alpha
vImage.SetBinding(Image.OpacityProperty, binding2)

alpha = 1
translation.X = -150

您的不透明属性如何知道alpha是否已更改? 绑定的自动更新依赖于属性更改时的通知。使用依赖项属性或实现INotifyPropertyChanged的类

因此,在您的情况下,alpha需要是一个依赖属性或实现INotifyPropertyChanged的某个类的属性


TranslateTransform将通知绑定有关更新的信息,因为“X”是TranslateTransform的依赖属性。因此,绑定可以连接更改事件并更新发生的绑定目标更改。

您的OpacityProperty如何知道alpha是否已更改? 绑定的自动更新依赖于属性更改时的通知。使用依赖项属性或实现INotifyPropertyChanged的类

因此,在您的情况下,alpha需要是一个依赖属性或实现INotifyPropertyChanged的某个类的属性


TranslateTransform将通知绑定有关更新的信息,因为“X”是TranslateTransform的依赖属性。因此,绑定可以连接更改事件并更新发生的绑定目标更改。

谢谢。最后,我在定义要绑定到的自定义对象的类中放置了一个image对象属性。最后效果很好,因为所有的道具都在那里,一切都在运行时完成。谢谢。最后,我在定义要绑定到的自定义对象的类中放置了一个image对象属性。最后效果很好,因为所有的道具都在那里,一切都在运行时完成。