首页 > 解决方案 > 单击我的按钮后,我的自定义输入更改颜色

问题描述

我正在处理呈现的自定义条目,当我单击我的按钮时,我需要在我的自定义呈现中听到 xaml

我的 xaml 中有这段代码

<local:MyEntry   eventRefresh="true">

当我单击我的按钮时,此功能已激活

private async void Execute(object sender)
        {
    var entry = ((MyEntry)view);
    entry.eventRefresh = "false";

但我的 EntryRendered 听不到变化

protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                var element = Element as MyEntry;               

标签: xamlxamarin.forms

解决方案


像这样制作您的视图模型。

public class YourViewModel

  {
    public Command command
    {
        get
        {
            return new Command(() => {

               //Change here button background colors
               BackgroundColor = Color.Green; 
            });
        }
    }


    private _backgroundColor = Color.White;
    public Color BackgroundColor
    {
        get { return _backgroundColor;}
        set
        {
             if (value == _backgroundColor)
                 return;

             _backgroundColor = value;
             NotifyOnPropertyChanged(nameof(BackgroundColor));
         }

}

}

你的 XAML

 <local:MyEntry Text="{Binding Password}" Placeholder="Enter"  />

<Button Text="send" Command="{Binding command}" BackgroundColor="{Binding BackgroundColor}"></Button>

推荐阅读