WPF Designer / Toolbox默认值 [英] WPF Designer/Toolbox default values

查看:91
本文介绍了WPF Designer / Toolbox默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个从TextBox派生的控件。它使用控件模板和样式来设置一些默认值。当我将它拖出工具箱并拖到表单上时,我会默认填写一些属性。它们似乎与TextBox具有相同的属性。我希望除了名称属性之外没有填写任何属性。

我尝试了线程,但每次控件在设计器或代码视图中获得焦点时都会调用Activate函数。这是不可接受的,因为用户输入的任何值都会被删除。

谢谢,

备用文件

I have created a control derived from TextBox.  It uses a control template and style to set some default values. When I drag it out of the toolbox and onto the form, I get some properties filled out by default.  They seem to be the same properties TextBox has.  I would like to not have any properties filled out except for the name property.

I tried the suggestions in this thread, but the Activate function is called every single time the control gets focus in the designer or code view.  This is not acceptable as any values the user entered get erased.

Thanks,

Frank


推荐答案

要控制设计人员生成的默认值,您的控件需要在控件的设计时程序集中实现DefaultIntializer;当您从设计界面上的工具箱创建控件时,此类由设计人员运行:

http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.defaultinitializer.aspx

如果你没有提供一个,那么将按照你观察到的那样运行基类1。如果基类没有基类,我们会应用一些简单的默认值。

感谢

标记

To control the default values that are generated by the designer, your control will need to implement a DefaultIntializer in the design time assembly for your control; this class is run by the designer when your control is created from the toolbox on the design surface:

http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.defaultinitializer.aspx

If you don't provide one, the base class one will be run instead as you've observed.  If the base class doesn't have one, we have some simple defaults we apply.

Thanks
Mark


这篇关于WPF Designer / Toolbox默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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