ConvertDpToPixels in Setter - for example HeaderRowHeight

Hi,

i try to understand why you use ConvertPixelsToDp in setter while returning pixel in getter. 

// throw
var
 tmp = grid.HeaderRowHeight;
grid.HeaderRowHeight = tmp;
if (tmp != grid.HeaderRowHeight)     
    throw new Exception("Not expected"); 

// do not throw
var tmp = grid.HeaderRowHeight;
grid.HeaderRowHeight = tmp;
if (grid.ConvertDpToPixels(tmp) != grid.HeaderRowHeight)
    throw new Exception("Not expected");


So I always get the height/width in px and have to put it in dp which is very confusing but may topped using Columns since the values will recalculated adding the column to grid.

Syncfusion.SfDataGrid.GridTextColumn col = new Syncfusion.SfDataGrid.GridTextColumn();
Syncfusion.SfDataGrid.GridTextColumn col2 = new Syncfusion.SfDataGrid.GridTextColumn();
col.MinimumWidth = 100;
double c1 = col.MinimumWidth;
grid.Columns.Add(col);
grid.Columns.Add(col2);
col2.MinimumWidth = 100;
 
double c2 = col2.MinimumWidth;
 
if (c1 != c2)
    throw new Exception("Unexpected");

so i need to check DataGrid property to know if i need convert to db or not. But this is not enough - if i doing:

Syncfusion.SfDataGrid.GridTextColumn col3 = new Syncfusion.SfDataGrid.GridTextColumn();
col3.MinimumWidth = 100; // MinimumWidth  = 100
grid.Columns.Add(col3);  // MinimumWidth  = 200
grid.Columns.Remove(col3);
grid.Columns.Add(col3); // MinimumWidth  = 400
Since your GridModel have no virtual methods, it is not possible to change the behavior.

How can i get and set the values always in the same unit (dp or px) without many workarrounds, knowing the context or implementationdetails of your components? At the moment there many potential traps and resulting bugs bec. it is unknown if the values are dp or px and even in dp if it is calced multible times. Your own components did not handle the differences between getter and setter correctly so i'm unshure how to get this behavior under control.




4 Replies

SK Suriya Kalidoss Syncfusion Team April 30, 2018 11:20 AM UTC

Hi Michael, 
Thank You for using Syncfusion Products, 
We had analyzed your query. We had internally used pixel values for smooth rendering in many devices and also for internal calculation in SfDataGrid, so we prefer to use pixel value. 
Based on your requirement to get DP value use sfGrid.ConvertPixelsToDp() extension. 
Regards, 
Suriya K 



MR Michael Roth April 30, 2018 01:10 PM UTC

Did you really read my post? If so, you kidnap me and we have to escalate this ticket, if not please read it again. If something was incomprehensible, I try to explain otherwise.



MR Michael Roth April 30, 2018 01:13 PM UTC

Did you really read my post? If so, you kidnap me and we have to escalate this ticket, if not please read it again. If something was incomprehensible, I try to explain otherwise.


SK Suriya Kalidoss Syncfusion Team May 4, 2018 01:47 AM UTC

Hi Michael, 
  
Sorry for inconvenience caused. 
  
We have checked your query. In SfDataGrid, the values you input in the sample level are considered to be dp values and we have internally converted the values to pixel values in the set property since Android handles rendering in pixel values. We have used the converted pixel values for all our internal logics to adapt the rendering of the data grid across devices with various display metrics. Therefore, the getter of the properties returns the pixel values. 
  
If we convert internally PixelsToDp value it leads to breaks in many height and width rendering cases, and hence we had exposed and extension method ConvertPixelsToDp() using which you can convert the pixel values to DP in the sample side. Please refer the below code snippet for clear understanding. 
  
Based on your requirement to get DP value use sfGrid.ConvertPixelsToDp() extension. 
Code logics: 
  col2.MinimumWidth = 100; 
 
  double c2 = col2.MinimumWidth; //Value=203 //Converted Pixel value for internal calculation 
 
  double Orginalvalue = sfGrid.ConvertPixelsToDp(c2); //Value =100 
   //Use ConvertPixelsToDp to obtain original value  
 
 
The following properties in SfDataGrid, need to be used with the given extension method for converting the obtained pixel values to DP.  
  • Header Row Height
  • Row Header Width
  • Row Height
  • SfDataGrid Height and Width
Column Properties: 
  • Column Width
  • Column Minimum Width
  • Column Maximum Width
 
We had prepared and attached working sample for your reference, you can download it from below link 
 
 
Regards, 
Suriya K 


Loader.
Up arrow icon