xaml - 单击我的按钮后,我的自定义输入更改颜色
问题描述
我正在处理呈现的自定义条目,当我单击我的按钮时,我需要在我的自定义呈现中听到 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;
解决方案
像这样制作您的视图模型。
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>
推荐阅读
- c# - 使用 .NET Core 进行跨平台开发时,我能否确保我的程序跨平台保持一致?
- windows - Docker 更改 Windows 上图像的默认路径
- google-apps-script - 为什么要复制所有值?
- python - How do I split a list so that it no longer has index values 0 or the end value?
- android - 我的选项菜单未显示在我的选项卡布局 Android Studio 上
- typescript - React Native 的环境变量无法使用 TypeScript
- javascript - 在 React 中使用表单将对象添加到数组
- python - 小python计算器错误
- java - 如何在android中使视图模糊
- javascript - 使用 Redux 更改 React 组件内部的状态