VB.net XAML UWP 可以共享 Class 用于 DataContext 吗?
VB.net XAML UWP Can Shared Class Be Used for DataContext?
我有一个 class 的对象,我已声明 'shared' 并且在使数据绑定正常工作时遇到了问题。我相信我的语法是正确的,所以我只想问一个基本问题,共享对象是否可以用作数据上下文?
没有
MSDN 说:
Static (shared) classes in C# and modules in Visual Basic have static
(shared) members only and cannot be instantiated.
这里 about the DataContext property:
A typical use of DataContext is to set it directly to a data source
object. This data source might be an instance of a class such as a
business object.
因此,UWP中的DataContext只能设置为一个对象的实例。在 WPF 中,我们可以使用共享(静态)classes 作为绑定源,但在 UWP 中不行。你需要一个对象。
我建议创建另一个 class 来提供对共享(静态)class 成员的访问权限。
我有一个 class 的对象,我已声明 'shared' 并且在使数据绑定正常工作时遇到了问题。我相信我的语法是正确的,所以我只想问一个基本问题,共享对象是否可以用作数据上下文?
没有
MSDN 说:
Static (shared) classes in C# and modules in Visual Basic have static (shared) members only and cannot be instantiated.
这里 about the DataContext property:
A typical use of DataContext is to set it directly to a data source object. This data source might be an instance of a class such as a business object.
因此,UWP中的DataContext只能设置为一个对象的实例。在 WPF 中,我们可以使用共享(静态)classes 作为绑定源,但在 UWP 中不行。你需要一个对象。
我建议创建另一个 class 来提供对共享(静态)class 成员的访问权限。