简体   繁体   English

WPF自定义控件模板

[英]WPF Custom control template

I have made one custom user control (search text box), which basically consists of one dock panel, and in the panel there are two controls: textbox and button. 我制作了一个自定义用户控件(搜索文本框),该控件基本上由一个停靠面板组成,并且该面板中有两个控件:文本框和按钮。

I have set some default appearance for this control, which consists of setting a border on the user control, and setting no borders and no background on the textbox, and I have created a custom style for the button. 我为此控件设置了一些默认外观,包括在用户控件上设置边框,在文本框上设置无边框和背景,并且为按钮创建了自定义样式。 So far this control looks the way I want, and is working correctly. 到目前为止,此控件看起来像我想要的方式,并且可以正常工作。

The problem arises when I want to allow themes for my application. 当我想为我的应用程序允许主题时,就会出现问题。 When I put custom styles for basic windows controls (Button, TextBox, ListBox, etc), they are displayed properly with the new theme. 当我为基本的Windows控件(按钮,文本框,列表框等)放置自定义样式时,它们会以新主题正确显示。 But I don't know how to make a template for my custom control. 但是我不知道如何为我的自定义控件创建模板。 Any attempt ended up in the control not showing at all at runtime. 任何尝试都会导致控件在运行时根本不显示。

What exactly must be done in the new template for this control? 在此控件的新模板中究竟必须做什么? Do I need to make a template for the User control, and for the textbox and the button controls also? 我是否需要为用户控件以及文本框和按钮控件创建模板?

You are mixing up user controls and custom controls here. 您在这里混合了用户控件和自定义控件。 What you described above is a user control, and you cannot apply new templates to it. 上面描述的是一个用户控件,您不能对其应用新模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM