简体   繁体   中英

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 (ie 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM