Click here to Skip to main content
15,888,322 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more: , +
hi there

i'm building a c# wpf multi-touch application which consists of multiple objects on the screen which can be manipulated using touch. these "information objects" will display various types of information such as text, webpages, images, video.

presently i have my objects defined in code, extending the Canvas class and programmatically adding all the visual elements. there are several types of information object, one for images, one for webpages, etc. but which all inherit from a base class for common functionality.

i would like to be able to use xaml to define the look of my objects, and i would like to be able to reuse them in other applications. i am thus considering rewriting my object classes as a library of custom controls.

i have tried following walkthroughs for how to do this seemingly simple task, but so far i have run into roadblocks. i would really appreciate if anyone could help me through producing a custom control?

1. i create a new project of type "WPF Custom Control Library" called InformationControlLibrary
2. i rebuild the project since Generic.xaml is giving an error
3. i rename the CustomControl1 class to ImageInformationControl
4. i create a new test project of type "WPF Application"
5. i create a reference to the custom control library in my test application.

i can now see my first control in the toolbox, but i can't use it yet as i still need to define it. i gather that i need to extend some visual element (probably UIElement?) but i can't change the CustomControl1 class from extending Control. where can i do this, and how can i edit the xaml? is it all done in generic.xaml for all of the controls?

i hope you can help, thanks for your time :)
Posted
Comments
Fredrik Bornander 19-Apr-11 12:13pm    
I do not understand what you mean by "still need to define it"?
If I follow your steps I can drag the CustomControl1 from the toolbox onto my MainWindow just fine.
ivan spams 20-Apr-11 7:14am    
i still need to write the control. i have got something going using user controls, which create a separate xaml file for each control in the library.

i suppose what i'm really asking is how the inheritance works with user controls. i want to create a basic user control that is extended in a variety of ways in order to support a variety of types of information.

ie how do i make my base control extend UIElement, and then my other controls extend my base control?

i hope that makes sense.

1 solution

you wrote:
"i gather that i need to extend some visual element (probably UIElement?) but i cant change the CustomControl1 class from extending Control"

Control is inherited from FrameworkElement which is inherited from UIElement :)

As I understand you want to create reusable CustomControl which will contain common functionality for other objects? What about to inherit your CustomCotrol from ContentControl instead of Control?

For example, in one of my projects I need create a lot of resizable controls on canvas. I created CustomControl which extends ContentControl and which implements resize feature.

After that I just put needed controls into Content of my custom resizable control, like:

<controls:resizablecontrol xmlns:controls="#unknown">
   <controls:foldernode title="Parent" />
</controls:resizablecontrol>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900