WPF在xaml中创建类的实例 [英] WPF Creating an instance of a class in xaml

查看:71
本文介绍了WPF在xaml中创建类的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 xaml 文件中创建类的实例时遇到问题.我以为你可以这样做:

I have a problem with creating the instance of a class in xaml file. I thought you can do it like this:

<src:MyDataClass x:Key="data"/>

在用户控件的资源部分,然后在xaml文件中使用(例如绑定到它).

in the resource part of the user control and then use it in the xaml file (for example bind to it).

但即使我创建的类也位于它所说的同一个命名空间中:

But even tough the class I created is located in the same namespace it says that:

未找到类型.验证所有程序集都已构建,等等".

"The type was not found. Verfiy that all assemblies were built, etc".

如何做对?还有其他方法吗?

How to get it right? is there another method?

感谢您的建议.

推荐答案

很明显,您必须向 xaml 添加正确的命名空间.包含要实例化的类的命名空间.阅读这篇后,您应该能够解决您的问题.

Well obviously you have to add the right namespace to your xaml. The namespace which contains the class you want instantiate. After reading this, you should be able to solve your problem.

这篇关于WPF在xaml中创建类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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