WPF Custom control template - wpf

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.

Related

Silverlight TreeView in ComboBox (or just a custom dropdown control)

I was wondering if I can have a ComboxBox with a Treeview as the selector rather than a list?
I note that there is a ComboBox.ItemsPanelTemplate, but I don't know what I need to do to get this to work?
I could build a control 'from the ground-up' with a separate TextBox, Button and TreeView in a PopUp control, but wondered if there is an easier way.
Lee
Are you just wanting the combobox for presentation purposes regarding the treeview?
Why not use a treeview as is and just trigger the display via visibility or animation from a button or control of some sort?
I am working on similar theme as we speak. I am using the Expander control from the Silverlight Toolkit with a TreeView control inside it. When an item is selected in the TreeView, it sets the Header of the Expander and then collapses the Expander.
Initial tests indicate it's OK but as I say, just started with it myself. Will let you know if I hit any stumbling blocks.

Content presenter inside user control

I'm developing my custom menu. It behaves like this. I have one toggle button and pathListBox that positioning menu items (buttons) into circle. So I have Menu user control that contains toggle button and one pathListBox. So I don't know how to put menu items inside pathListBox. I want to write
<my:Menu>
<my:MenuItem>
</my:MenuItem>
</my:Menu>
How to get this content of the user control into pathListBox.
Tnx!
Consider building a true Control or ItemsControl; UserControl derives from ContentControl and is not well-suited to building controls with many items being presented.

Auto-complete in WPF - Making a popup unfocusable

I'm trying to create a custom UserControl that will mimic auto-complete as it works within Intellisense using WPF. I'm using a TextBox and a Popup containing a ListBox within my control.
I want to be able to keep keyboard focus set on the TextBox irrespective of whether or not the auto-completion popup is open so that a user can continue typing whilst simultaneously using up/down controls or the mouse to select elements in the popup to autocomplete the text. Is there any way this can be done in WPF?
Check out my article on CodeProject, it addresses the issue of the popup specifically.
A Reusable WPF Autocomplete TextBox

When writing the xaml for my user controls should I remove grid and use dock panel or something else?

I am adding user controls in my solution. The main page of my project will have a dock panel. When writing the xaml for my user controls should I remove grid and use dock panel or what? Iam using visual studio express and WPF.
The answer is it depends on what you want your control to look like.
Remember the Grid is to help you orgainze your controls. You can define features like columns widths, row heights, and other styling.
While a dock panel is to help dock your control to a part of the form or another.
So it depends on what you want your control to look like. You can nest a grid in a dock panel and vice versa. There is no set rule. It is really up to you.
Inside your user controls, use whatever type of panel makes sense for the contents of that control. In the main page, you set the DockPanel.Dock attribute on your user control, but that is independent of what's inside the user control.
It really depends on what you want to do.
Your top level may not even be a panel. For example, if you only want one control in the user control, then you really don’t need the panel.
Also, in some cases, even with composite controls, you may want to put something other than a panel as the top level control, for example, an expander.
Further, if you want to create a control that is very similar to another control, but behaves a little different, you may not even want to use a user control and instead inherit from an existing control. An example of this would be a numeric textbox that inherits from a textbox but adds keypress filtering.

WPF Custom Control Design question

I have a design question:
If you had to make a WPF Combobox with search support,
(= combobox that shows a popup with some Buttons, Search TextBox, List.. etc
the selected item feed to the default's ComboBox TextBox.)
What would you do?
Write a custom control (diretly inheriting from System.Windows.Control)
Write a custom control inheritnig from Selector / ComboBox
Make a UserControl
Use a default ComboBox with a 'special Template' (CotnrolTemplate/Style ?) extended to search functionality
Use a default ComboBox with style and attached EventHandlers..
Thank you guys !
I have done that, and the method i used was option 2 - i did a template control inheriting from a third party combo, and replaced the popup contents with my own template.

Resources