Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Custom Control with different styles or templates?

I'm having a WPF Custom Control which represents me a given point on a plan (I'm making a guide application for my studies) and I want it to looks different for different categories of the objects represented by this map node (i.e. toilet, lift or normal room).
Could anyone give me some idea how to do this?

I tried creating a Converter but it didn't goes well. Also my problem is that sometimes in could be the WPF element like Ellipse and sometimes it should be an image.

Is it somehow possible to create custom control with multiple templates and the template will be selected depending on some category attribute?

like image 633
Pax0r Avatar asked May 18 '11 08:05

Pax0r


1 Answers

For things like this, you might want to have a look at the DataTemplateSelector class. It allows you to select the datatemplate based on the actual object you are binding to.

Here's a tutorial for it, but i'm sure you can find more on the internet: http://www.switchonthecode.com/tutorials/wpf-tutorial-how-to-use-a-datatemplateselector

like image 77
Botz3000 Avatar answered Sep 28 '22 00:09

Botz3000