开发者

WPF c# dynamically switch Itemtemplate when object class gets changed

I've got the following scenario: WPF Treeview displaying custom objects, eac开发者_StackOverflow中文版h of them containing a list of children. So the problem is: Each of the custom objects is controlled by a combobox that can change the current object from Class A to Class B/C/D and vice versa. Classes A-D are all subclasses of a superclass. So far so good. Each class should be represented by a specific Datatemplate in the WPF treeview, so each time, the user changes the object class (using the inline-combo) the item should get a new template applied. So far I've tried:

  1. DataTemplate Selector Class (gets only applied at start)
  2. "nulling" DatatemplateSelector in treeview and reappling it after object change (too slow)
  3. Datatemplate by class (x:Type) (works, but I need three different Templates per Object, one graphic, one minimum, one maximum display width with additional TextBlocks)
  4. Datatrigger (I do not know how to databind it to the changed Class)

Might be some kind of systematic mistake. Your help is appreciated very much

Greets

Markus


The last solution is the best way to go (datatemplate on datatype)but in your datatemplate set the content to a contentcontrol with a datatrigger on the style property. overriding the control template based on your trigger precondition. alternatively you may want to consider a hierarchicaldatatemplate.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜