c# - WPF DataGrid validation - showing tooltip around in cell -


i have datagrid looks that:

<datagrid columnwidth="45" canuseraddrows="false" headersvisibility="none" itemssource="{binding correctionmatrixa, converter={staticresource matrixtodatatable}}">                            <datagrid.rowvalidationrules>       <validators:matrixvalidationrule validationstep="updatedvalue"/>    </datagrid.rowvalidationrules> </datagrid> 

i don't know nothing columns until runtime - converter converts custom object datatable , binds it. how can use validator show errors in typing when cannot use

<datagrid.columns> 

and define styles there? there solutions?

edit:

converter:

    public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         var casted = value simplematrix;         if (casted == null)             return binding.donothing;          var width = casted.width;         var height = casted.height;          var datatable = new datatable();          (var c = 0; c < width; c++)         {             datatable.columns.add(new datacolumn());         }          int k = 0;         (int = 0; < height; i++)         {             var newrow = datatable.newrow();             (int j = 0; j < width; j++)             {                 newrow[j] = casted.fields.single(a => a.x == && a.y == j).value;                 k++;             }             datatable.rows.add(newrow);         }         return datatable.defaultview;     } 

simplematrix generated xsd object.

validation:

    public override validationresult validate(object value, cultureinfo cultureinfo)     {         var group = (bindinggroup)value;         foreach (var item in group.items)         {             var row = ((datarowview)item).row;              foreach (datacolumn column in row.table.columns)             {                 var result = validatecell(column.columnname, row);                 if (result != validationresult.validresult)                 {                     return result;                 }             }         }         return validationresult.validresult;      }      private validationresult validatecell(string columnname, datarow row)     {          datatable table = row.table;         var column = table.columns[columnname];         object cellvalue = row[column.columnname];          if (string.isnullorempty(cellvalue?.tostring()))         {             return new validationresult(false, "cell cannot null");         }          if (column.datatype == typeof(string))         {             if (((string)cellvalue).any(c => !char.isdigit(c) && c != ',' && c != '.'))             {                 return new validationresult(false, "only digits , separator allowed");             }         }         return validationresult.validresult;     } 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -