Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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[^]
 
Share this answer
 
Comments
Espen Harlinn 17-Dec-12 12:55pm    
Nice idea :-D
Wendelius 17-Dec-12 14:20pm    
Thanks Espen, even though it's seems that it's not what OP is after :)
Espen Harlinn 17-Dec-12 15:34pm    
Then he is probably looking for information on the DataTemplateSelector
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
 
Share this answer
 
Comments
Tall Bill Clark 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900