从 XAML 调用参数化构造函数 [英] Calling a parameterized constructor from XAML

查看:37
本文介绍了从 XAML 调用参数化构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 WPF 时,我注意到当我向 XAML 文件添加控件时,会调用默认构造函数.

While using WPF I noticed that when I add a control to a XAML file, the default constructor is called.

有没有办法调用参数化构造函数?

Is there a way to call a parameterized constructor?

推荐答案

.NET 4.0 带来了一项挑战答案的新功能 - 但显然仅适用于 UWP 应用程序(而非 WPF).

.NET 4.0 brings a new feature that challenges the answer - but apparently only for UWP applications (not WPF).

x:Arguments 指令

<object ...>
    <x:Arguments>
        oneOrMoreObjectElements
    </x:Arguments>
</object>

这篇关于从 XAML 调用参数化构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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