简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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