The requested page is not available for the requested platform. You are viewing the content for Default platform.

EditRowViewModel Class

Contains information on a data row that a user currently edits via the edit form.

Namespace: DevExpress.XamarinForms.DataGrid

Assembly: DevExpress.XamarinForms.Grid.dll

Declaration

public class EditRowViewModel :
    INotifyPropertyChanged

Remarks

An EditRowViewModel object serves as a data context (binding source) for a template that defines the presentation of the grid's edit form (EditFormPage).

Examples

This example shows how to create a custom view for the grid's edit form and set up the grid to invoke this form when a user double taps a cell.

The grid is bound to a collection of Employee objects and contains columns to display employee information (photo, name, position, phone, address, hire and birth dates, access level, and information about vacation). A custom edit form will display an employee's photo and name, and contain editors to modify employee's phone and address.

Follow the steps below to implement a custom edit form.

  1. Define a data template to be a content for the edit form page. In this example, it is a Xamarin.Forms.Grid with a set of labels and editors inside. Its BindingContext is an EditRowViewModel object. Use its Source property to access an object that represents a data source's record (Employee) and bind editors to its properties.

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                x:Class="DataGridExample.MainPage"
                xmlns:dxg="clr-namespace:DevExpress.XamarinForms.DataGrid;assembly=DevExpress.XamarinForms.Grid">
        <ContentPage.Resources>
            <DataTemplate x:Key="CustomEditFormContent">
                <ScrollView>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding Path=Source.Photo}" Grid.Row="0" Grid.Column="0"/>
                        <StackLayout Orientation="Vertical" Padding="50, 20, 0, 0" Grid.Row="0" Grid.Column="1">
                            <Label Text="{Binding Path=Source.Name}"  VerticalOptions="Start"
                                   FontSize="20" FontAttributes="Bold" />
                            <StackLayout Orientation="Horizontal">
                                <Label Text="Phone:"  FontSize="14" WidthRequest="100"
                                       HorizontalOptions="Start" VerticalOptions="Center" />
                                <Editor Text="{Binding Path=Source.Phone, Mode=TwoWay}" 
                                        FontSize="Small" HorizontalOptions="FillAndExpand"/>
                            </StackLayout>
                            <StackLayout Orientation="Horizontal">
                                <Label Text="Address:"  FontSize="14" WidthRequest="100"
                                       HorizontalOptions="Start" VerticalOptions="Center" />
                                <Editor Text="{Binding Path=Source.Address, Mode=TwoWay}" 
                                        FontSize="Small" HorizontalOptions="FillAndExpand"/>
                            </StackLayout>
                        </StackLayout>
                    </Grid>
                </ScrollView>
            </DataTemplate>
        </ContentPage.Resources>
        <!-- ... -->
    </ContentPage>
    
  2. In the grid's RowDoubleTap event handler, create an EditFormPage instance and pass the specified data template to its constructor as a third parameter.

    <dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}" 
                      RowDoubleTap="Grid_RowDoubleTap">
        <!-- ... -->
    </dxg:DataGridView>
    
  3. In the App.xaml.cs file, assign a NavigationPage instance to the Application.MainPage property and add the MainPage content page to the navigation stack (the application's root page):

    namespace DataGridExample {
        public partial class App : Application {
            public App() {
                InitializeComponent();
    
                // MainPage = new MainPage();
                MainPage = new NavigationPage(new MainPage());
            }
    
            // ...
        }
    }
    

Inheritance

Object
EditRowViewModel
See Also