Skip to content

SyncfusionExamples/Xamarin-DataGrid-Column-Properties-Binding-MVVM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to bind and control the column properties on SfDataGrid using the MVVM pattern.

This article demonstrates how to bind and control the column properties on SfDataGrid.

To achieve this, a bindable property is exposed in the ViewModel. This property remains synchronized with the grid’s current selection and also updates the grid when its value changes from the ViewModel, ensuring two-way communication between the UI and the data layer.

Xaml#:

<sfgrid:SfDataGrid
                ItemsSource="{Binding State}"
                AutoGenerateColumns="True">
                <sfgrid:SfDataGrid.Columns>
                    <sfgrid:GridTextColumn MappingName="Name" CellTextSize="{Binding TextSize}"/>
                </sfgrid:SfDataGrid.Columns>
</sfgrid:SfDataGrid>

C#:

class ViewModel : INotifyPropertyChanged
{
    public double TextSize
    {
        get { return textSize; }
        set
        {
            textSize = value;
            OnPropertyChanged(nameof(TextSize));
        }
    }
}

About

Describes how to set values to the properties of the columns in Xamarin DataGrid via binding from view model

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6

Languages