简体   繁体   English

创建模板时,是否有任何理由要使用后端C#初始化程序?

[英]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.

相关问题 有什么办法可以在使用C#后端时加快向页面添加新元素的速度吗? - Is there any way that I can speed up the adding of new elements to a page when using the C# back end? 如何在具有C#后端而不是XAML的模板上绑定XAML元素? - How can I bind a XAML element on a template with the C# back end instead of in the XAML? 如何在C#后端的模板中更改标签的颜色? - How can I change the color of a Label in a template in the C# back end? 在C#后端中将资源声明为Class时,如何访问资源? - How can I access a resource when it's declared as a Class in C# back end? ZipStorer未在Android C#中创建任何文件 - ZipStorer not creating any file in Android c# 如何将命令传递给模板并让它在我的后端代码中执行并传递参数? - How can I pass a command to a template and have it execute in my back end code and pass the parameter? 我可以将XAML网格的高度绑定回我的C#后端代码吗? - Can I bind the Height of a XAML Grid back to my C# back end code? 创建模板 class 并添加事件时,是否需要删除它? - When creating a template class and adding an event is there any need to remove it? 在C#后端,如何在分段控件中选择元素? - In the C# back end, how can I select an element in a Segmented Control? 如何将DynamicResource的值发送到自定义控件C#后端? - How can I send the value of a DynamicResource to my custom controls C# back end?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM