MainWindow() 和 GetXmlData() 工作正常并在 gridview 上显示 xmlfile。但是当我包含 XmlNode :IDataErrorInfo 类时,它停止工作。
我喜欢让所有这些都工作以显示和验证网格视图。任何人都可以发现我想念的东西吗?或者解释一下,我在这里停下来。这似乎是 observablecollection 之间的错误。
public MainWindow()
{
InitializeComponent();
RadGridView testGrid = new RadGridView();
testGrid.ItemsSource = GetXmlData();
testGrid.AutoGenerateColumns = false;
GridViewDataColumn col1 = new GridViewDataColumn();
col1.DataMemberBinding = new Binding("JobKey") {
ValidatesOnDataErrors = true, NotifyOnValidationError = true };
testGrid.Columns.Add(col1);
LayoutRoot.Children.Add(testGrid);
}
private static object GetXmlData()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\\JobSetupFile.xml");
XmlDataProvider provider = new XmlDataProvider();
provider.IsAsynchronous = false;
provider.Document = doc;
provider.XPath = "JobSetup/JobParameters";
return new ObservableCollection<XmlNode>((IEnumerable<XmlNode>)provider.Data);
}
public class XmlNode : IDataErrorInfo
{
public string JobKey { get; set; }
public XmlNode()
{
}
public string Error
{
get { throw new NotImplementedException(); }
}
public string this[string columnName]
{
get
{
string result = string.Empty;
if (columnName.Equals("JobKey"))
{
if (JobKey.Where(s => Char.IsLetter(s)).Count() != JobKey.Length)
result = "Invalid name format. Name should contain letters only";
}
return result;
}
}
}