It's my first experience with WPF. And I'm developing an Inventory Management System. My design model has single Window, in which a frame loads different Pages while clicking on different buttons. While adding a new Inventory into the Database, I want to ensure Data Validation. I choose IDataErrorInfo in this regard. I have to implement the interface but unable to implement just writing as public partial class AddInventoryPage : Page, IDataErrorInfo
. This shows error. The signature of the class is as following
public partial class AddInventoryPage : Page
I also tried as under but unable to achieve the functionality. Even I put a breakpoint within IDataErrorInfor part but the control doesn't go there.
namespace IMS
{
public partial class AddInventoryPage : IDataErrorInfo
{
//code here
}
public partial class AddInventoryPage : Page
{
//code here
}
}
As My Inventory module is completed except Data Validation, and I'm working on the Sales module; it's not a solution to change my design model. Moreover, I'm not using any Design Pattern like MVVM. It's straight. Looking forward to a solution.
example with a validation against the property 'Name'
public class AddInventoryPage : IDataErrorInfo
{
public string Name { get; set; }
public string Error => null;
public string this[string columnName]
{
get
{
switch(columnName)
{
case nameof(Name):
if (Name == string.Empty) return "Name can not be empty";
}
return string.Empty;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.