[英]How can I change the color of a Label in a template in the C# back end?
I have this template that's simplified for the question: 我有一个简化了此问题的模板:
<?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>
and this C# 和这个C#
using Xamarin.Forms;
namespace Japanese.Templates
{
public partial class RoundButtonText : BaseFrameButtonTemplate
{
public RoundButtonText()
{
InitializeComponent();
?? = Color.Red;
}
}
}
Can someone help me by telling me how I can change the TextColor of the label in the XAML inside the constructor of the back-end C#. 有人可以通过告诉我如何在后端C#的构造函数中更改XAML中的标签的TextColor来帮助我。 Note that there's much more to this but I'm simplifying what I need for the question as if I know this then I can do the rest.
请注意,这还有很多事情要做,但是我正在简化我需要解决的问题,好像我知道这一点一样,那么我就可以做剩下的事情。
Specify x:Name="MyLabel"
on the Label you want to access. 在要访问的标签上指定
x:Name="MyLabel"
。
Then you can access that Label in your back-end C# file like so: 然后,您可以像这样在后端C#文件中访问该Label:
public RoundButtonText()
{
InitializeComponent();
MyLabel.TextColor = Color.Red; //OR
MyLabel.BackgroundColor = Color.Red;
}
That allows you to be able access any public property on the Label 这样您就可以访问Label上的任何公共财产
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.