Custom control
-
Hello I am having difficulty finding an article / tutorial on how to create a custom control that derives from System.Windows.Controls.Control class using a ControlTemplate to display visuals. I find most of my search queries just return results for UserControl or deriving from another class (TextBox etc). Could someone please provide me a link if they know of one. Thank you. -Mike
-
Hello I am having difficulty finding an article / tutorial on how to create a custom control that derives from System.Windows.Controls.Control class using a ControlTemplate to display visuals. I find most of my search queries just return results for UserControl or deriving from another class (TextBox etc). Could someone please provide me a link if they know of one. Thank you. -Mike
This[^] may go some way towards what you are looking for. I would also suggest any other articles by the author, Sacha Barber, or alternatively, Josh Smith. Further, both these legends provide links to other authors who they recommend, which is in itself the best recommendation you are likely to see.
-
This[^] may go some way towards what you are looking for. I would also suggest any other articles by the author, Sacha Barber, or alternatively, Josh Smith. Further, both these legends provide links to other authors who they recommend, which is in itself the best recommendation you are likely to see.
Thanks Richard, but not quite what I am looking for. The control I am currently working on originated as a derived class of System.Windows.Controls.Panel. I got this to a point where I was happy with measure and arrange overrides of child objects. I wanted this container/panel to have a visual style to be applied to it, as well as the option to create alternate control templates. I changed the derived class from System.Windows.Controls.Panel to System.Windows.Controls.Control . At this point I lost the rendering of my control. I am looking for some information on how to get the rendering of this object back, also how to set a control template for it. Do I need to override any rendering code when working with a base class of System.Windows.Controls.Control? I have tried to use a control template in the way I would have used it for a control derived off another base class eg. SearchTextBox : TextBox DefaultStyleKeyProperty.OverrideMetadata(typeof(SearchTextBox), new FrameworkPropertyMetadata(typeof(SearchTextBox))); CustomControl : Control DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl), new FrameworkPropertyMetadata(typeof(CustomControl))); When I try to view this template in Blend I get the following error. Unable to cast object of type 'Microsoft.Expression.DesignSurface.ArtboardBorder' to type 'ParentOfCustomControl' (The custom control has a fixed Parent type which is derived from System.Windows.Controls.Grid)
-
Thanks Richard, but not quite what I am looking for. The control I am currently working on originated as a derived class of System.Windows.Controls.Panel. I got this to a point where I was happy with measure and arrange overrides of child objects. I wanted this container/panel to have a visual style to be applied to it, as well as the option to create alternate control templates. I changed the derived class from System.Windows.Controls.Panel to System.Windows.Controls.Control . At this point I lost the rendering of my control. I am looking for some information on how to get the rendering of this object back, also how to set a control template for it. Do I need to override any rendering code when working with a base class of System.Windows.Controls.Control? I have tried to use a control template in the way I would have used it for a control derived off another base class eg. SearchTextBox : TextBox DefaultStyleKeyProperty.OverrideMetadata(typeof(SearchTextBox), new FrameworkPropertyMetadata(typeof(SearchTextBox))); CustomControl : Control DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl), new FrameworkPropertyMetadata(typeof(CustomControl))); When I try to view this template in Blend I get the following error. Unable to cast object of type 'Microsoft.Expression.DesignSurface.ArtboardBorder' to type 'ParentOfCustomControl' (The custom control has a fixed Parent type which is derived from System.Windows.Controls.Grid)