WPF Designer / Toolbox默认值

编程入门 行业动态 更新时间:2024-10-22 15:42:56
本文介绍了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;当您从设计界面上的工具箱创建控件时,此类由设计人员运行: msdn.microsoft/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:msdn.microsoft/en-us/library/microsoft.windows.design.model.defaultinitializer.aspxIf 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.ThanksMark

更多推荐

WPF Designer / Toolbox默认值

本文发布于:2023-11-07 06:24:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:默认值   WPF   Designer   Toolbox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!