XAML数据绑定到常规属性 [英] XAML databinding to regular property

查看:107
本文介绍了XAML数据绑定到常规属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WPF / XAML中尝试数据绑定。我已经写了一个相机控件,它绑定到XAML中的PerspectiveCamera的TransformProperty,如下所示:

I am currently experimenting with data binding in WPF/XAML. I have written a camera control that binds to the TransformProperty of a PerspectiveCamera in XAML like this:

<PerspectiveCamera FieldOfView="60" UpDirection="0,1,0" Transform="{Binding
 CameraControlVM.CamControl.Transform}"/>

CameraControlVM只是我的ViewModel类。 CamControl有一个常规的.Net属性Transform,它用作绑定源。

The CameraControlVM is just my ViewModel class. The CamControl has a regular .Net property Transform which is used as binding source here.

public class CameraControl 
{
    public Transform3D Transform { get; set; }
...
}

所以一切都很好,但实际上我我想知道为什么?当我的相机控制变换变化时,束缚透视相机的变换也会改变。在这种情况下,我绑定了一个目标(PerspectiveCamera.Transform),它是一个DependencyProperty作为一个常规属性(Transform)作为源。我没有在我的CameraControl上实现INotifyPropertyChanged接口,所以在数据绑定方面,我期望只有相机控制转换应该被通知实际相机变换的变化,而不是相反。我在这里缺少一些东西或混淆数据绑定规则?

So Everything works fine, but actually I am wondering why?! When the transform of my camera control changes, the transform of the bound perspective camera changes as well. In this situation I have bound a target (PerspectiveCamera.Transform) which is a DependencyProperty to a regular property (Transform) as a source. I have not implemented the INotifyPropertyChanged Interface on my CameraControl, so in terms of databinding I expect only the camera control transform should be informed about changes of the actual camera transform and not the other way round. Am I missing something here or confusing the databinding rules?

使问题更加清晰:在我的设置中,常规的属性似乎通知DependencyProperty当它改变WITHOUT使用INotifyPropertyChanged和我认为这是不可能的数据绑定,是吗?
也许它与由WPF中的Animatable导出的Transform3D有关系?

To make the question more clear: In my setup a regular property seems to inform a DependencyProperty when it is changing WITHOUT using INotifyPropertyChanged and I thought this is not possible in data binding, is it? Maybe it has something to do with Transform3D deriving from Animatable in WPF?

推荐答案

让我尝试清除混淆

变形 CameraControl 类中的普通属性所以更改属性的值不会触发任何通知,因此UI将无法响应

The Transform is a normal property in CameraControl class so changing the value of the property will not fire any notification and hence UI will not be able to respond

另一方面,Transform的类型是 Transform3D ,它来自 DependencyObject ,因此可以通知实例中的任何属性更改。

on the other hand type of Transform is Transform3D which is derived from DependencyObject and hence is capable of notifying any property change within the instance.

所以在运行时本质上如果你改变了Transform属性的值,这些值不会反映到UI

So in essence during runtime if you change the value of Transform property that will not reflect to UI

eg。

cam.Transform = new Transform3D();

其中,如果您修改将反映到UI的Transform3D实例的属性

where as if you modify the properties of the Transform3D instance that will be reflected to UI

例如。

cam.Transform.Value = new Matrix3D();

我希望能够清除混淆。

这篇关于XAML数据绑定到常规属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆