Wpf custom control - wpf

I have a customn control which display a window with another custom control inside. The developper can redefine the control template, it works but I don't find a way to allow developper to redefine the template of control inside the window that the custom control display...

Ok, I found. The solution is simply to set the other control as a dependency property inside the first (parent) control...

Related

How to unload a custom user control programatically in Silverlight?

I want to unload a user control on the click of a button inside the user control. I am calling this user control inside navigation:page for the filtering the rad gridview.
I think Making the visibility collapsed wont unload it.
Any ideas?
Remove it from visualtree. Suppose that your control "myControl" is contained within Panel derivate called "LayoutRoot" then you can do this:
LayoutRoot.Children.Remove(myControl).

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.

Quickest way to inherit a standard control in WPF?

I just want to wrap a standard control with some more additional properties (look stay the same, I don't want to do theming in first stage).
Can I just inherit from this standard control instead of UserControl or Control ? In fact I read it is obligatoryb to use Custom Control Project Template and not UserControl ontrol Project Template. Why ?
Update: I try with a Custom Control Project and inherit from the standard slider but I have nothing show up visually ! Now what should I do to have the same visual slider as the standard one ?
I know the difference between a user control and a custom control but in practice how do you do when you just want ONE single standard control ? How will a slider for example resize AUTOMATICALLY if I encapsulate it inside a User Control instead of a Custom Control ?
A custom control is a single control and can derive from another control, this would support styling. A UserControl is a composite control out of many different controls, and as a whole, doesn't support styling (the parts do however).
If you want to add features of any kind to an existing control, derive from it. If you want to pack several controls together to make it easier to handle them (you could still add DP's to it), use a UserControl.
A custom control alone won't do anything related to resizing etc, that is dependent on the settings you supply to it from the outside (ie. HorizontalAlignment, VerticalAlignment and others) when you used it in a container. The custom control should inherit the default template from the base class unless you override it.

Templates in extended Silverlight controls

i am looking to extend a third party control, it is a ComboBox (so it isn't the standard Silverlight one, but that shouldn't matter for this question). To do this, i add a new template control to my controls project, then i change the new control to inherit from ComboBox instead of Control. A style has been created for me in the generic.xaml file, so i delete the default border stuff that was inserted, and then add a property setter for the PopupTemplate.
My problem is that when doing it this way, the combobox doesn't (visibly) render in the silverlight application anymore. However, in the constructor of my extension if i comment out the line
this.DefaultStyleKey = typeof(MyComboBox);
and put the PopupTemplate xaml bit in the main silverlight page, it renders correctly. I want the popup template to be declared within the control library, but does this mean that i also have to define the regular Template property? Am i wrong in thinking that anything i don't explicitly specify should just be inherited from the base control?
A control can only have one default style. You need to copy the entire default style of the base control into the Generic.Xaml for you new MyComboBox then adjust it accordingly.

WPF: Custom Window

There are many articles that described how to create a custom shaped window in WPF but none of them (at least I can't find any) described how can build a reusable one such as inheriting from it in other windows.
I have tried to create a ControlTemplate from my custom window. The problem is with the Close button and the MoveDrag() method.
If I wire the event to one of my other controls in ControlTemplate their Parent property is null, so I can not drag or close the window.
Does anyone have any ideas how can I create a reusable custom window template or something?
Unfortunately there is no such things as visual inheritance in WPF. (no xaml inheritance to be more specific)
For your specific issue, instead of inheriting, you could create a CustomForm as a template (with a big empty container in the middle), and then create all your other forms as usercontrols that fill that container.
The following will return the window object containing the control:
Window.GetWindow(myControl)

Resources