xamarin表单中评级页面模块的动态XAML内容 [英] Dynamic XAML content for a rating page module in xamarin forms

查看:80
本文介绍了xamarin表单中评级页面模块的动态XAML内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

要求是我需要有一个评级页面。我们将在数据库中提出问题,我们需要根据问题数量动态实施评级控制。我假设我们需要在后端(.cs文件)中创建控件。我们将使用syncfusion控件SfRating。关于如何在后面的代码中创建xaml设计的任何想法或示例代码?





我尝试过:



完成SFRating控制的一些研究。正在进行的实施研究。

解决方案

您可以使用字符串或字符串构建器类在C#中将XAML代码添加为纯字符串。 XAMLReader类用于读取,解析和呈现XAML代码。以下是定义和设置模板的示例代码。确保在XAML字符串中包含所有别名和名称空间。



 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'Inource ='img / details.png');
sb.Append(x:Name ='imgDetails'/>);
sb.Append (< / Canvas>);
sb.Append(< / DataTemplate>);

TabControl.Template =(DataTemplate)System.Windows.Markup.XamlReader。负载(sb.ToString());


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.

解决方案

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());


这篇关于xamarin表单中评级页面模块的动态XAML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆