Xamarin Android with mvvmcross

Hi so I am using MVVMCross Xamarin android (NOT Xamarin forms) and I have a class Node.cs that has many properties but I only want to display status,number, description and comment. The status column has a xml layout that I want to display as a progressbar with a icon in the ring. How do I do this?
    <Syncfusion.SfDataGrid.SfDataGrid 
            local:MvxBind="ItemClick ChildClicked; ItemsSource Display;"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/sfDataGrid1"
// need to add columns here and state layout file for the column
local:allowSorting="true"/>
    

6 Replies 1 reply marked as answer

SS Sivaraman Sivagurunathan Syncfusion Team July 23, 2020 09:45 AM UTC

Hi Shafaq, 

Thanks for using Syncfusion control. 

We have checked your query. If you want to generate the column manually you have to access the  SfDataGrid view using FindViewById<> from XAML file and set the property in code behind. And you can load any view inside the GridCell using UserCellType. We have prepared the sample based on your requirement and attached reference. You can download the same from the below link. 



protected override void OnCreate(Bundle savedInstanceState) 
    base.OnCreate(savedInstanceState); 
    SetContentView(Resource.Layout.Main); 
    dataGrid = FindViewById<SfDataGrid>(Resource.Id.sfDataGrid); 
    orderI = new ViewModel(); 
    dataGrid.ColumnSizer = ColumnSizer.None; 
    dataGrid.AutoGenerateColumns = false; 
    dataGrid.RowHeight = 100; 

    GridTextColumn employeeId = new GridTextColumn(); 
    employeeId.MappingName = "ID"; 
    dataGrid.Columns.Add(employeeId); 

    GridTextColumn customerIdColumn = new GridTextColumn(); 
    customerIdColumn.UserCellType = typeof(CustomCell); 
    customerIdColumn.MappingName = "Percentage"; 
    customerIdColumn.HeaderText = "Percentage"; 
    dataGrid.Columns.Add(customerIdColumn); 
    dataGrid.ItemsSource = orderI.Info; 



public class CustomCell : GridCell 
    LinearLayout layout; 
    RadioButton radioButton; 

    public CustomCell(Context context) : base(context) 
    { 
        layout = new LinearLayout(this.Context); 
        radioButton = new RadioButton(this.Context); 
        radioButton.TextAlignment = TextAlignment.Center; 
        layout.AddView(radioButton); 
        this.AddView(layout); 
    } 

    protected override void UnLoad() 
    { 
        if (this.Parent != null) 
            (this.Parent as VirtualizingCellsControl).RemoveView(this); 
    } 

    protected override void OnLayout(bool change, int l, int t, int r, int b) 
    { 
        this.layout.Layout(0, 0, this.Width, this.Height); 
    } 

    protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) 
    { 
        base.OnMeasure(widthMeasureSpec, heightMeasureSpec); 
        this.layout.Measure(widthMeasureSpec, heightMeasureSpec); 
    } 

    protected override void OnDraw(Canvas canvas) 
    { 
        base.OnDraw(canvas); 
    } 



Regards, 
Sivaraman S 



SA Shafaq Arshad July 24, 2020 08:32 AM UTC

Hi 

so I actually wanted to use a xml layout for a column cell and the maybe inflate the cell view using mvvmcross binding

public class CustomCell : GridCell 
    LinearLayout layout; 
    RadioButton radioButton; 

    public CustomCell(Context context) : base(context) 
    { 
        //bindinginflate.Inflate(Resource.Id.layout):
    } 

    protected override void UnLoad() 
    { 
        if (this.Parent != null) 
            (this.Parent as VirtualizingCellsControl).RemoveView(this); 
    } 

    protected override void OnLayout(bool change, int l, int t, int r, int b) 
    { 
        this.layout.Layout(0, 0, this.Width, this.Height); 
    } 

    protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) 
    { 
        base.OnMeasure(widthMeasureSpec, heightMeasureSpec); 
        this.layout.Measure(widthMeasureSpec, heightMeasureSpec); 
    } 

    protected override void OnDraw(Canvas canvas) 
    { 
        base.OnDraw(canvas); 
    } 


SS Sivaraman Sivagurunathan Syncfusion Team July 27, 2020 11:29 AM UTC

Hi Shafaq, 

Thanks for your update. 

We have checked your query. you can load the custom view using xml layout using Inflate. We have prepared the sample based on your requirement and attached for your reference you can download the same from the below link. 


public class CustomCell : GridCell 
{ 
    LinearLayout layout; 
    public CustomCell(Context context) : base(context) 
    { 
        layout = new LinearLayout(this.Context); 
        LayoutInflater inflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService); 
        View view = inflater.Inflate(Resource.Layout.CustomLayout, null, false); 
        layout.AddView(view); 
        this.AddView(layout); 
    } 
 
    protected override void UnLoad() 
    { 
        if (this.Parent != null) 
            (this.Parent as VirtualizingCellsControl).RemoveView(this); 
    } 
 
    protected override void OnLayout(bool change, int l, int t, int r, int b) 
    { 
        this.layout.Layout(0, 0, this.Width, this.Height); 
    } 
 
    protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) 
    { 
        base.OnMeasure(widthMeasureSpec, heightMeasureSpec); 
        this.layout.Measure(widthMeasureSpec, heightMeasureSpec); 
    } 
 
    protected override void OnDraw(Canvas canvas) 
    { 
        base.OnDraw(canvas); 
    } 
} 



Regards, 
Sivaraman S 



SA Shafaq Arshad July 28, 2020 11:01 AM UTC

I am getting this 
System.NotSupportedException: 'Unable to activate instance of type Syncfusion.SfDataGrid.GridHeaderCellControl from native handle 0x75 (key_handle 0xfb54b5c).'
any idea why?
I am trying to use custom header template and trying to bind it a view using mvvmcross


Attachment: tel_f2a42c6a.zip


SA Shafaq Arshad July 28, 2020 11:38 AM UTC

It comes when I change visibilty of the list


SS Sivaraman Sivagurunathan Syncfusion Team July 29, 2020 01:12 PM UTC

Hi Shafaq, 

Thanks for you update. 

We have checked your query and you can achieve your requirement  by using xml layout using Inflate. We have prepared the sample based on your requirement and attached for your reference you can download the same from the below link.  


public class MainActivity : Activity 
{ 
    private SfDataGrid dataGrid; 
    private ViewModel orderI; 
 
    protected override void OnCreate(Bundle savedInstanceState) 
    { 
        base.OnCreate(savedInstanceState); 
        SetContentView(Resource.Layout.Main); 
        dataGrid = FindViewById<SfDataGrid>(Resource.Id.sfDataGrid); 
        orderI = new ViewModel(); 
        dataGrid.ColumnSizer = ColumnSizer.None; 
        dataGrid.AutoGenerateColumns = false; 
        dataGrid.RowHeight = 100; 
 
        GridTextColumn employeeId = new GridTextColumn(); 
        employeeId.MappingName = "ID"; 
        dataGrid.Columns.Add(employeeId); 
 
        GridTextColumn customerIdColumn = new GridTextColumn(); 
        customerIdColumn.HeaderTemplate = GenerateView("Percentage"); 
        customerIdColumn.MappingName = "Percentage"; 
        customerIdColumn.HeaderText = "Percentage"; 
        dataGrid.Columns.Add(customerIdColumn); 
        dataGrid.ItemsSource = orderI.Info; 
    } 
 
    private View GenerateView(string text) 
    { 
        LayoutInflater inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService); 
        View view = inflater.Inflate(Resource.Layout.CustomLayout, null, false); 
        (view as TextView).SetText(text, TextView.BufferType.Normal); 
        return view; 
    } 
} 




Regards, 
Sivaraman S 


Marked as answer
Loader.
Up arrow icon