DropdownSetting.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Controls.Primitives;
  4. using System.Windows.Data;
  5. namespace PixiEditor.Models.Tools.ToolSettings.Settings
  6. {
  7. public class DropdownSetting : Setting<object>
  8. {
  9. public DropdownSetting(string name, string[] values, string label)
  10. : base(name)
  11. {
  12. Values = values;
  13. Value = ((ComboBox)SettingControl).Items[0];
  14. Label = label;
  15. }
  16. public string[] Values { get; set; }
  17. private ComboBox GenerateDropdown()
  18. {
  19. ComboBox combobox = new ComboBox
  20. {
  21. VerticalAlignment = VerticalAlignment.Center
  22. };
  23. GenerateItems(combobox);
  24. Binding binding = new Binding("Value")
  25. {
  26. Mode = BindingMode.TwoWay
  27. };
  28. combobox.SetBinding(Selector.SelectedValueProperty, binding);
  29. return combobox;
  30. }
  31. private void GenerateItems(ComboBox comboBox)
  32. {
  33. for (int i = 0; i < Values.Length; i++)
  34. {
  35. ComboBoxItem item = new ComboBoxItem
  36. {
  37. Content = Values[i]
  38. };
  39. comboBox.Items.Add(item);
  40. }
  41. }
  42. public override Control GenerateControl()
  43. {
  44. return GenerateDropdown();
  45. }
  46. }
  47. }