【发布时间】:2019-02-11 13:27:25
【问题描述】:
我正在为 Windows 10 制作 UWP 商店应用程序。我使用 API 并连接到服务器。
我只需要将无效登录的错误消息绑定到文本框。但是在调用方法 OnPropertyChanged eventHandler 时总是返回 null 值?
public LoginPasswordView()
{
this.InitializeComponent();
var vm = new LoginPasswordViewModel(new NavigationService(), new LoginService());
this.DataContext = vm;
}
viewmodel.cs
public class LoginPasswordViewModel : MainViewBaseModel
{
private string password;
private string errorMessage="We need this info to countinue";
public LoginPasswordViewModel(INavigationService navigationService, ILoginService loginService)
{
_navigationService = navigationService;
_loginService = loginService;
}
private INavigationService _navigationService { get; set; }
private ILoginService _loginService { get; set; }
public string Errormessage
{
get
{
return errorMessage;
}
set
{
errorMessage = value;
OnPropertyChanged("Errormessage");
}
}
}
public class MainViewBaseModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
var eventHandler = this.PropertyChanged;
if (eventHandler != null)
eventHandler(this, new PropertyChangedEventArgs(propertyName));
}
}
XAML:
<TextBlock Text="{Binding Path=Errormessage,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Margin="250,25,0,0" FontSize="24" FontFamily="Segoe Pro" Foreground="Red"/>
【问题讨论】:
-
请在 XAML 中显示您的绑定表达式。
-
-
您好,在向问题添加信息时,请对其进行编辑并添加。这可确保用户无需通读 cmets 即可全面了解您面临的问题。
-
欢迎来到 Stack Overflow!其他用户将您的问题标记为低质量和需要改进。我重新措辞/格式化您的输入,使其更易于阅读/理解。请查看我的更改以确保它们反映您的意图。如果您对我有其他问题或反馈,请随时给我留言。
-
@GhostCat 谢谢。这就是我的意思
标签: uwp inotifypropertychanged