gpt4 book ai didi

data-binding - Xamarin.Forms 刷新编辑器的 TextProperty

转载 作者:行者123 更新时间:2023-12-05 04:16:53 25 4
gpt4 key购买 nike

有没有办法在事件发生后更改编辑器单元格中的文本?

我有一个显示来自 SQLite 数据库的地址的编辑器单元格。我还有一个按钮,可以获取当前地址并在警报中显示该地址,询问他们是否愿意将地址更新为此。如果是,那么我想在编辑器单元格中显示新地址。

public class UserInfo : INotifyPropertyChanged
{
public string address;
public string Address
{
get { return address; }
set
{
if (value.Equals(address, StringComparison.Ordinal))
{
return;
}
address = value;
OnPropertyChanged();
}
}

public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

我的编辑器单元格代码是

Editor userAddress = new Editor
{
BindingContext = uInfo, // have also tried uInfo.Address here
Text = uInfo.Address,
Keyboard = Keyboard.Text,

};

然后在它得到当前地址后我有这个

bool response = await DisplayAlert("Current Address", "Would you like to use this as your address?\n" + currAddress, "No", "Yes");
if (response)
{
//we will update the editor to show the current address
uInfo.Address = currAddress;
}

如何让它更新编辑器单元格以显示新地址?

最佳答案

您正在设置控件的 BindingContext,但未指定与之配套的绑定(bind)。您想要将编辑器的 TextProperty 绑定(bind)到上下文的 Address 属性。

Editor userAddress = new Editor
{
BindingContext = uinfo,
Keyboard = Keyboard.Text
};

// bind the TextProperty of the Editor to the Address property of your context
userAddress.SetBinding (Editor.TextProperty, "Address");

这也可以,但我不确定语法是否正确:

Editor userAddress = new Editor
{
BindingContext = uinfo,
Text = new Binding("Address"),
Keyboard = Keyboard.Text
};

关于data-binding - Xamarin.Forms 刷新编辑器的 TextProperty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25985013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com