尝试通过字符串将文本绑定到我的xaml,并使用propertychanged函数根据int的值更改文本.这是我的代码:
XAML:
<Label Text = "{Binding Forename}" />
Run Code Online (Sandbox Code Playgroud)
码:
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged (string propertyName)
{
var changed = PropertyChanged;
if (changed != null) {
PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
}
}
string info;
int myInt = 0;
public string Forename {
get {
return info;
}
set {
if (myInt == 0) {
info = value;
OnPropertyChanged ("TextOne");
}
else if (myInt == 1)
{
OnPropertyChanged ("TextTwo");
}
else
{
OnPropertyChanged ("TextThree");
}
}
} …Run Code Online (Sandbox Code Playgroud)