开发者

Rendering dynamic user control attributes from database in Silverlight c#

I am working on program that will render questionnaire forms from a database using Silverlight with C#.

I currently have it rendering UserControls based on a Question records "Control" field. "Textbox", "Label" etc etc.

Im just wondering if it's possible to load attributes for these controls based on an attributes table. For instance I would have an Attributes table containing name val开发者_运维百科ue pairs such as "Padding, 10", "Margin, 5" etc etc. linked to a particular Question.

Should create a method that will apply these attributes based on a large case statement. I've also though of using reflection but this may give a big performance hit. Are there any better solutions?

Thanks.


I've found a solution. Beforehand I was rendering textboxes just using the Controls classes. Now I am building up the XAML and using XamlReader.Load() to turn the xaml into a control class.

public UIElement GetControl()  
{  
  StringBuilder sb = new StringBuilder();    
  sb.Append("<TextBox xmlns='http://schemas.microsoft.com/client/2007'> ");  
  sb.Append(Model.QuestionAttributes.DrawAttributes());  
  sb.Append("/>");  
  TextBox Textbox = XamlReader.Load(sb.ToString()) as TextBox;  

  return Textbox as TextBox;       
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜