RootLabelView.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace AIPractice.LabelEditor
  16. {
  17. /// <summary>
  18. /// Interaction logic for RootLabelView.xaml
  19. /// </summary>
  20. public partial class RootLabelView : UserControl
  21. {
  22. public RootLabelView()
  23. {
  24. InitializeComponent();
  25. }
  26. private void OnDeleteClick(object sender, RoutedEventArgs e)
  27. {
  28. if (MessageBox.Show("确认删除此标签吗?", "删除标签", MessageBoxButton.YesNo, MessageBoxImage.Question) ==
  29. MessageBoxResult.Yes)
  30. {
  31. var rootLabelViewModel = DataContext as RootLabelViewModel;
  32. if (rootLabelViewModel != null)
  33. {
  34. App.Container.Labels.Remove(rootLabelViewModel);
  35. }
  36. }
  37. }
  38. private void OnUpDownClick(object sender, UpDown e)
  39. {
  40. var rootLabelViewModel = DataContext as RootLabelViewModel;
  41. if (rootLabelViewModel != null)
  42. {
  43. var rootLabel = rootLabelViewModel.RootLabel;
  44. var index = App.Container.Labels.IndexOf(rootLabelViewModel);
  45. if (e == UpDown.Up)
  46. {
  47. if (index > 0)
  48. {
  49. App.Container.Container.Labels.Remove(rootLabel);
  50. App.Container.Labels.Remove(rootLabelViewModel);
  51. App.Container.Container.Labels.Insert(index -1,rootLabel);
  52. App.Container.Labels.Insert(index - 1, rootLabelViewModel);
  53. }
  54. }
  55. else
  56. {
  57. if (index < App.Container.Labels.Count - 1)
  58. {
  59. App.Container.Container.Labels.Remove(rootLabel);
  60. App.Container.Labels.Remove(rootLabelViewModel);
  61. App.Container.Container.Labels.Insert(index + 1, rootLabel);
  62. App.Container.Labels.Insert(index + 1, rootLabelViewModel);
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }