private void combo_joysticks_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (guids.Count <= 0 || combo_joysticks.SelectedIndex < 0) { return; } Stop(); buttonsToColors = new ObservableCollection <JoystickButtonToColor>(); App.settings.JoystickSelected = guids[combo_joysticks.SelectedIndex].ToString(); App.settings.Save(); foreach (var item in joystickHelper.LoadJoystickButtons(guids[combo_joysticks.SelectedIndex])) { buttonsToColors.Add(item); } for (int i = 0; i < buttonsToColors.Count; i++) { var item = buttonsToColors[i]; if (item.ButtonType == JoystickButtonToColor.ButtonTypeEnum.Color) { var panel = new ButtonColorPicker(item); panel.colorPanel.ColorChanged += ColorPanel_ColorChanged; ContextMenu context = new ContextMenu(); MenuItem menu = new MenuItem(); menu.Header = "Remove"; menu.Click += Item_Click; context.Items.Add(menu); menu.Uid = i.ToString(); panel.ContextMenu = context; StackColors.Children.Add(panel); } else { var panel = new ButtonBrightnessPicker(item); ContextMenu context = new ContextMenu(); MenuItem menu = new MenuItem(); menu.Header = "Remove"; menu.Click += Item_Click; context.Items.Add(menu); menu.Uid = i.ToString(); panel.ContextMenu = context; StackColors.Children.Add(panel); } } Start(); }