public void InitView() { if (_isDesignTime == true) { return; } GridView = Content as EditableGridView; var viewModelObject = ViewModelFactory.CreateViewModel <T>(); ViewModel = viewModelObject as IEditableGridViewModel <T>; ViewModel.SaveCommand = new SimpleCommand("SaveCommand", () => { Logger.Instance.Info(_debugName + " Save", Logger.Categories.Data); GridView.dataGrid.CommitEdit(DataGridEditingUnit.Row, true); ViewModel.Save(); ActionAfterSave?.Invoke(); }); ViewModel.LoadCommand = new SimpleCommand("LoadCommand", () => { Logger.Instance.Info(_debugName + " Load", Logger.Categories.Data); GridView.dataGrid.CommitEdit(DataGridEditingUnit.Row, true); ViewModel.Load(); ActionAfterLoad?.Invoke(); }); DataContext = ViewModel; for (int i = 0; i < ViewModel.HeaderFilters.Count; i++) { foreach (var column in GridView.Columns) { if (column.Header.ToString() == ViewModel.HeaderFilters[i].PropertyName) { column.Header = ViewModel.HeaderFilters[i]; break; } } } }
public void InitView() { if (_isDesignTime == true) { return; } _logger.LogDebug("InitView {0}", ViewName); GridView = Content as EditableGridView; if (ViewModel == null) { var viewModelObject = ViewModelFactory.CreateViewModel <T, T1>(); ViewModel = viewModelObject as IEditableGridViewModel <T1>; } ViewModel.ShowDialogAction = (content, title) => { var w = new Window() { Title = title, WindowStartupLocation = WindowStartupLocation.CenterScreen, Content = content, Owner = Window.GetWindow(this) }; w.ShowDialog(); }; ViewModel.SaveCommand = new SimpleCommand("SaveCommand", () => { _logger.LogInformation("Save {0}", ViewName); GridView.dataGrid.CommitEdit(DataGridEditingUnit.Row, true); ViewModel.Save(); ActionAfterSave?.Invoke(); }, () => CanSave()); ViewModel.LoadCommand = new SimpleCommand("LoadCommand", () => { _logger.LogInformation("Load {0}", ViewName); GridView.dataGrid.CommitEdit(DataGridEditingUnit.Row, true); ViewModel.Load(); ActionAfterLoad?.Invoke(); }); DataContext = ViewModel; for (int i = 0; i < ViewModel.HeaderFilters.Count; i++) { var filter = ViewModel.HeaderFilters[i]; if (filter.IsShowInUI == false) { continue; } foreach (var column in GridView.Columns) { if (column.Header.ToString() == filter.PropertyName) { column.Header = filter; break; } } } }