![](/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.