private void MainDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { lock (selectionLock) { var grid = (DataGrid)sender; var setting = grid.SelectedItems.Cast <UserSetting>().FirstOrDefault(); _CurrentUserSetting = setting; // Get device attached to user setting. _CurrentUserDevice = setting == null ? new UserDevice() : SettingsManager.GetDevice(setting.InstanceGuid); // Get mappings attached to user setting. _CurrentPadSetting = setting == null ? new PadSetting() : SettingsManager.GetPadSetting(setting.PadSettingChecksum); DPadPanel.SetBinding(_CurrentPadSetting); GeneralPanel.SetBinding(MappedTo, _CurrentPadSetting); AdvancedPanel.SetBinding(_CurrentPadSetting); LeftTriggerPanel.SetBinding(_CurrentPadSetting); RightTriggerPanel.SetBinding(_CurrentPadSetting); LeftThumbXPanel.SetBinding(_CurrentPadSetting); LeftThumbYPanel.SetBinding(_CurrentPadSetting); RightThumbXPanel.SetBinding(_CurrentPadSetting); RightThumbYPanel.SetBinding(_CurrentPadSetting); ForceFeedbackPanel.SetBinding(MappedTo, _CurrentPadSetting); ForceFeedbackPanel.LeftForceFeedbackMotorPanel.SetBinding(_CurrentPadSetting, 0); ForceFeedbackPanel.RightForceFeedbackMotorPanel.SetBinding(_CurrentPadSetting, 1); PadFootPanel.SetBinding(MappedTo, _CurrentUserDevice, _CurrentPadSetting); SettingsManager.Current.LoadPadSettingsIntoSelectedDevice(MappedTo, _CurrentPadSetting); OnSettingChanged?.Invoke(this, new EventArgs <UserSetting>(setting)); } }
/// <summary> /// Load pad setting into control /// </summary> public void LoadPadSetting(Guid?padSettingChecksum) { // Load PadSetting object from configuration. PadSetting ps = null; if (padSettingChecksum.HasValue) { ps = SettingsManager.GetPadSetting(padSettingChecksum.Value); } if (ps == null) { ps = new PadSetting(); } // Stop monitoring changes. CurrentPadSetting.PropertyChanged -= CurrentPadSetting_PropertyChanged; // Load values into current object which is attached to all controls. CurrentPadSetting.Load(ps); // Rebind pad setting to controls. DPadPanel.SetBinding(CurrentPadSetting); GeneralPanel.SetBinding(MappedTo, CurrentPadSetting); AdvancedPanel.SetBinding(CurrentPadSetting); LeftTriggerPanel.SetBinding(CurrentPadSetting); RightTriggerPanel.SetBinding(CurrentPadSetting); LeftThumbXPanel.SetBinding(CurrentPadSetting); LeftThumbYPanel.SetBinding(CurrentPadSetting); RightThumbXPanel.SetBinding(CurrentPadSetting); RightThumbYPanel.SetBinding(CurrentPadSetting); ForceFeedbackPanel.SetBinding(MappedTo, CurrentPadSetting); ForceFeedbackPanel.LeftForceFeedbackMotorPanel.SetBinding(CurrentPadSetting, 0); ForceFeedbackPanel.RightForceFeedbackMotorPanel.SetBinding(CurrentPadSetting, 1); PadFootPanel.SetBinding(MappedTo, _CurrentUserDevice, CurrentPadSetting); // Start monitoring changes. CurrentPadSetting.PropertyChanged += CurrentPadSetting_PropertyChanged; //SettingsManager.Current.LoadPadSettingsIntoSelectedDevice(MappedTo, CurrentPadSetting); }