开发者

data-binding, IDataErrorInfo and complex properties naming

开发者 https://www.devze.com 2023-03-17 07:45 出处:网络
lets say I have MyClass.cs in which I have a property called Name, then I have my viewModel which inherits IDataErrorInfo, where I created multible instances of MyClass in this viewModel and added the

lets say I have MyClass.cs in which I have a property called Name, then I have my viewModel which inherits IDataErrorInfo, where I created multible instances of MyClass in this viewModel and added them all to an ObservableCollection< MyClass> , this collection will be the ItemsSource of a DataGrid , and surly one of it's DataGridTextColumn is bound to Name property, this wrks really good as in the following XAML

<DataGridTextColumn Binding="{Binding  Name}" Header="Name" IsReadOnly="True" />

all good , now I need to supply a column name for the IDataErrorInfo, as follows

string IDataErrorInfo.this[string columnName]
    {
        get 
        { 
           string error = String.Empty;
           switch (columnName)
           {
               case "WhatToPutHere":
                   error = validateName();
                   return error;
               default:
                   开发者_运维问答throw new ApplicationException("Wrong Property name being validated");
           }
        }
    }

the problem is , I don't have this "Name" property here in my viewModel , it is there on MyClass.cs , so I don't know what to supply the IDataErrorInfo Column name with , I tried Name and MyClass.Name both didn't work out , any suggestions ?? Thanks in advance


The name of the property. In this case it's Name


If you are not sure what to put there, why not put a test line of code such as msgbox(columnname). Then run your application (or part of it) and see what pops up. Hope this helps.


I figured it out , I had to implement IDataErorInfo there on MyClass.cs not on the viewModel

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号