![](/img/trans.png)
[英]How can I bind a XAML element on a template with the C# back end instead of in the XAML?
[英]How can I change the color of a Label in a template in the C# back end?
我有一个简化了此问题的模板:
<?xml version="1.0" encoding="UTF-8"?>
<Frame xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:t="clr-namespace:Japanese.Templates"
xmlns:local="clr-namespace:Japanese;assembly=Japanese"
x:Class="Japanese.Templates.RoundButtonText" x:Name="this">
<Label Text="ABC" />
</Frame>
和这个C#
using Xamarin.Forms;
namespace Japanese.Templates
{
public partial class RoundButtonText : BaseFrameButtonTemplate
{
public RoundButtonText()
{
InitializeComponent();
?? = Color.Red;
}
}
}
有人可以通过告诉我如何在后端C#的构造函数中更改XAML中的标签的TextColor来帮助我。 请注意,这还有很多事情要做,但是我正在简化我需要解决的问题,好像我知道这一点一样,那么我就可以做剩下的事情。
在要访问的标签上指定x:Name="MyLabel"
。
然后,您可以像这样在后端C#文件中访问该Label:
public RoundButtonText()
{
InitializeComponent();
MyLabel.TextColor = Color.Red; //OR
MyLabel.BackgroundColor = Color.Red;
}
这样您就可以访问Label上的任何公共财产
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.