开发者

WPF: How to dynamically find a usercontrol or datatemplate

开发者 https://www.devze.com 2022-12-30 23:43 出处:网络
I have a bunch of datatemplates I use to display various sql-views in an ItemsControl. I don\'t know which datatemplate i\'m going to use until run-time. (every view has different columns)

I have a bunch of datatemplates I use to display various sql-views in an ItemsControl. I don't know which datatemplate i'm going to use until run-time. (every view has different columns) Next to that, I made a开发者_运维技巧 generic dynamic datatemplate for all those views that don't need anything special.

When I display the view I want to first look in all the available datatemplates if there is one that matches, else use the default dynamic datatemplate.

My question is how can I 'search' a datatemplate by name in code? Usercontrol is also possible.

Thanks,

Elger


Yep got it:

Use a datatemplateselector or just use window.FindResource to do the trick.

This helped me:
http://www.developingfor.net/net/dynamically-switch-wpf-datatemplate.html

0

精彩评论

暂无评论...
验证码 换一张
取 消