Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

The requirement is I need to have a rating page. We will be getting the questions in the database and we need to have a dynamic implementation of Rating control base on the number of questions. I am assuming that we need to create the controls in the backend(.cs file). We will be using the syncfusion control SfRating. Any idea or sample codes on how to create a xaml design in the code behind?


What I have tried:

Done some research for SFRating control. Ongoing research for the implementation.
Posted
Updated 15-Feb-19 23:49pm

1 solution

You can add XAML code as plain string in C# using a string or a string builder class. XAMLReader class is used to read, parse and render XAML code. Here is an sample code to define and set a template. Make sure to include all aliases and namespaces in XAML string.

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<DataTemplate ");
sb.Append("xmlns='http://schemas.microsoft.com/winfx/");
sb.Append("2006/xaml/presentation' ");
sb.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
sb.Append("xmlns:local = 'clr-namespace:yournamespace');

sb.Append(";assembly=<yourassembly>'>");

sb.Append("<Canvas Width='150'>");
sb.Append("<TextBlock Width='Auto' Canvas.Left='35' Canvas.Top='2' Text='{Binding Field1}' />");

sb.Append("<Image Height='20' Width='20' Canvas.Top='2' Canvas.Left='3' Source='img/details.png' ");
sb.Append("x:Name='imgDetails' />");
sb.Append("</Canvas>");
sb.Append("</DataTemplate>"); 

 TabControl.Template = (DataTemplate)System.Windows.Markup.XamlReader.Load(sb.ToString());
 
Share this answer
 

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