Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XAML
Quick question:
Is is short work using XAML to have the types of controls configured/controlled by the underlying data. I see plenty of examples of configuration of a control's look/feel based on data content; I am looking to base the control type on the associated data/properties.
 
Examples include:
. Value returns Bool object, the control should be a button
. Value returns Int32 object, the control should be a textbox
or
. The data could expose a property, Widget, that would specify button, textbox, etc
 
I suppose one could write this in C# pretty readily or cobble together a ContentControl that contains all possible button, textbox, etc combination and the data could control which are visible but these seem such hacks. I thought I would ask the experts if a more natural xaml solution exists.
Posted 17-Dec-12 6:18am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Depending on the situation, one possibility could be to build a custom control that handles 'individual controls'. This custom control would adapt to the data type etc.
 
Another option could be to use a property grid such as Wpf Toolkit - PropertyGrid[^] or for example Native WPF 4 PropertyGrid[^]
  Permalink  
Comments
Espen Harlinn at 17-Dec-12 12:55pm
   
Nice idea :-D
Mika Wendelius at 17-Dec-12 14:20pm
   
Thanks Espen, even though it's seems that it's not what OP is after :)
Espen Harlinn at 17-Dec-12 15:34pm
   
Then he is probably looking for information on the DataTemplateSelector
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If the PropertyGrid isn't what you're looking for then I guess you're looking for something like WPF Based Dynamic DataTemplateSelector[^]
 
Best regards
Espen Harlinn
  Permalink  
Comments
Tall Bill Clark at 17-Dec-12 17:27pm
   
Nail hit on on head. This is very much what I was looking for.
 
I may have skimmed thru this before but dismissed it when I saw the size of the code involved thinking "this *has* to be easier". I can accept that it isn't easier. Even the write up allows that this looks burdonsome but still pays off when there are many types that need to be matched and managed. Thanks!
Espen Harlinn at 17-Dec-12 17:30pm
   
Brilliant :-D

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 310
1 CPallini 310
2 George Jonsson 269
3 Gihan Liyanage 255
4 OriginalGriff 245
0 OriginalGriff 4,903
1 CPallini 3,960
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,786
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100