如何在XAML中创建类的实例? [英] How to create instance of class in XAML?

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

问题描述

我想创建一个没有可视元素的简单实用程序类,并在XAML中创建它,以便可以定义数据绑定。我试图创建从 DependencyObject 派生的类,并在 Window.Resources 部分中创建它,但是它没有调用任何构造函数

I want to create simple utility class that has no visual elements and create it in XAML so I can define databindings. I tried to create class derived from DependencyObject and create it in Window.Resources section but it doesn't call any constructor.

推荐答案

看起来像实例是在您实际使用它们时创建的。我发现此问题的肮脏解决方法-将 FindResource( myClass); 放在主窗体构造函数中。

Looks like instances are created when you actually use them. I've found dirty workaround for this problem - to place FindResource("myClass"); in main form constructor.

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

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