MainWindow.xaml.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using SourceChord.FluentWPF;
  2. using System.Linq;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Media;
  7. namespace Phihong_EVSE_UI_Tool
  8. {
  9. /// <summary>
  10. /// MainWindow.xaml 的互動邏輯
  11. /// </summary>
  12. public partial class MainWindow : Window
  13. {
  14. private ListViewItem lastSelectedItem = null;
  15. private InitialIdleUC ucInitialIdle = new InitialIdleUC();
  16. private AuthenticationUC ucAuthentaction = new AuthenticationUC();
  17. private PlugChargingUC ucPlugCharging = new PlugChargingUC();
  18. private MaintenanceUC ucMaintenance = new MaintenanceUC();
  19. private BuildIco ucBuildIco = new BuildIco();
  20. private ModifyIco ucModifyIco = new ModifyIco();
  21. public MainWindow()
  22. {
  23. InitializeComponent();
  24. this.MaxHeight = SystemParameters.WorkArea.Height + 12.5;
  25. this.MinWidth = 1200;
  26. this.MinHeight = 800;
  27. uxInitListViewItem.IsSelected = true;
  28. uxInitListViewItem.Focus();
  29. }
  30. private void uxMenuListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  31. {
  32. if (uxMenuListView.SelectedItem != null)
  33. {
  34. if (lastSelectedItem != null)
  35. {
  36. lastSelectedItem.Foreground = new SolidColorBrush(Colors.Black);
  37. lastSelectedItem.Background = null;
  38. }
  39. ListViewItem item = uxMenuListView.SelectedItem as ListViewItem;
  40. Binding myBinding = new Binding("ImmersiveSystemAccentBrush");
  41. myBinding.Source = new AccentColors();
  42. item.SetBinding(ListViewItem.ForegroundProperty, myBinding);
  43. item.Background = new SolidColorBrush(Color.FromArgb(45, 0, 0, 0));
  44. uxTitleTextBlock.Text = (item.Content as StackPanel).Children.OfType<TextBlock>().First().Text;
  45. uxContentGrid.Children.Clear();
  46. switch (item.Name)
  47. {
  48. case "uxInitListViewItem":
  49. uxContentGrid.Children.Add(ucInitialIdle);
  50. uxContentGrid.Children.OfType<InitialIdleUC>().First().uxContentScrollViewer.ScrollToTop();
  51. break;
  52. case "uxAuthListViewItem":
  53. uxContentGrid.Children.Add(ucAuthentaction);
  54. uxContentGrid.Children.OfType<AuthenticationUC>().First().uxContentScrollViewer.ScrollToTop();
  55. break;
  56. case "uxChargingListViewItem":
  57. uxContentGrid.Children.Add(ucPlugCharging);
  58. uxContentGrid.Children.OfType<PlugChargingUC>().First().uxContentScrollViewer.ScrollToTop();
  59. break;
  60. case "uxMaintainListViewItem":
  61. uxContentGrid.Children.Add(ucMaintenance);
  62. uxContentGrid.Children.OfType<MaintenanceUC>().First().uxContentScrollViewer.ScrollToTop();
  63. break;
  64. case "uxBuildListViewItem":
  65. uxContentGrid.Children.Add(ucBuildIco);
  66. uxContentGrid.Children.OfType<BuildIco>().First().uxContentScrollViewer.ScrollToTop();
  67. break;
  68. case "uxModifyListViewItem":
  69. uxContentGrid.Children.Add(ucModifyIco);
  70. uxContentGrid.Children.OfType<ModifyIco>().First().uxContentScrollViewer.ScrollToTop();
  71. break;
  72. default:
  73. break;
  74. }
  75. lastSelectedItem = item;
  76. }
  77. }
  78. }
  79. }