xamarin - 如何在 C# 后端的模板中更改标签的颜色?
问题描述
我有这个针对问题进行了简化的模板:
<?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# 文件中访问该标签:
public RoundButtonText()
{
InitializeComponent();
MyLabel.TextColor = Color.Red; //OR
MyLabel.BackgroundColor = Color.Red;
}
这使您能够访问标签上的任何公共属性
推荐阅读
- reactjs - 为什么我的自定义挂钩会导致无限数据重新获取?
- javascript - 增量 ID 并将数据推送为数字 - 谷歌 Firebase 和本机反应
- python - 使用子进程从 C++ 程序获取返回值到 Python 脚本
- python - 如何从python中的父/子继承json中检索数据?
- flutter - Flutter:读取 BloC 状态的 Stream 数据,如果 UI 发生变化,则重新渲染 UI
- elasticsearch - ElasticSearch:在具有复杂对象的数组中查找多个唯一值
- python - 遍历 Python 日志文件实际上并没有遍历内容并给我不同的条目
- reactjs - React hooks - 将数组重新初始化为空
- jquery - jQuery datepicker - 无法选择日期
- c# - .NET Core Jwt 无法解析服务