<StackLayout> <Button x:Name="btn1" Command="{Binding AddRowCommand}" CommandParameter="{x:Reference dataGrid}" Text="ClickToAddRow" /> <Button x:Name="btn2" Command="{Binding AddColumnCommand}" CommandParameter="{x:Reference dataGrid}" Text="ClickToAddColumn" /> <sfGrid:SfDataGrid ………> </StackLayout> // In ViewModel public ViewModel() { _addRow = new Command(ExecuteAddRow); _addColumn = new Command(ExecuteAddColumn); } #region Command methods private void ExecuteAddRow(object obj) { this.OrdersInfo.Insert(0,new OrderInfo() { OrderID = 10000, Country = "US", CustomerID = "Alfki",Freight = "345", IsClosed = true }); } private void ExecuteAddColumn(object obj) { var dataGrid = obj as SfDataGrid; (obj as SfDataGrid).Columns.Insert(0,new GridTextColumn() { MappingName = "OrderID" }); } #endregion #region Commands private Command _addRow; public Command AddRowCommand { get { return _addRow; } set { _addRow = value; } } private Command _addColumn; public Command AddColumnCommand { get { return _addColumn; } set { _addColumn = value; } } #endregion |
dataGrid.GridLoaded += DataGrid_GridLoaded; private void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e) { var firstColumn = dataGrid.Columns[0]; var firstRow = dataGrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowType == RowType.DefaultRow).RowData; } |