[英]When creating a template is there any reason to have a back end C# initializer?
I have this example in my application: 我的应用程序中有以下示例:
<?xml version="1.0" encoding="utf-8"?>
<Grid xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:J;assembly=J"
x:Class="J.Templates.HelpGrid"
Padding="15"
RowSpacing="10"
ColumnSpacing="10" />
and in c# 和在C#中
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace J.Templates
{
public partial class HelpGrid : Grid
{
public HelpGrid()
{
InitializeComponent();
}
}
}
From what I see the code works and I can use that template without or without my coding a back end c#. 从我看到的代码可以正常工作,我可以使用该模板,而无需编写或不编写后端c#。
Is there any reason why the developer might have chosen to add the back end C# code? 开发人员可能有任何理由选择添加后端C#代码吗?
The backing class (c# file) is needed by the compiler to work, at this time you cant avoid it. 编译器需要后备类(c#文件)才能工作,这时您无法避免。
In theory, it is possible to eliminate the need of the backing class, but it's not an easy thing to do. 从理论上讲,可以消除对支持类的需求,但这并不是一件容易的事。
They could add a new task in the compile pipeline but this will slow the build a lot (more xaml, more slow). 他们可以在编译管道中添加新任务,但这会大大降低构建速度(xaml越多,速度越慢)。
At the end there is very little benefits and a lot of works, its not worth. 最后,收益很少,还有很多工作,这是不值得的。
You can read the full explanation, made by the Xamarin staff, here: https://github.com/xamarin/Xamarin.Forms/issues/4327#issuecomment-436921856 您可以在这里阅读Xamarin工作人员的完整说明: https : //github.com/xamarin/Xamarin.Forms/issues/4327#issuecomment-436921856
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.