最近我开始使用 Xamarin.Forms 进行开发。我正在创建一个必须自定义按钮的应用程序,因此我创建了 customButton 类。现在,我想使用 object.name 属性访问自定义类中的按钮,但我无法做到这一点。谁能建议我如何做到这一点。
代码
<local:CustomButton x:Name="signInButton" Text="Sign In" Clicked="OnLoginButtonClicked" TextColor ="White" FontSize="15" FontAttributes="Bold"/>
Android项目中的CustomButton类
namespace Sample.Droid
{
class CustomButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
//Want to access button name in if condition, instead of Control.
//Hope this will help you all in understanding my problem.
}
}
}
}
谢谢