BottomView.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. namespace Aitex.Core.UI.View.Frame
  15. {
  16. /// <summary>
  17. /// Interaction logic for BottomView.xaml
  18. /// </summary>
  19. ///
  20. partial class BottomView : UserControl
  21. {
  22. public event Action<string> ButtonClicked;
  23. public BottomView()
  24. {
  25. InitializeComponent();
  26. btnBackward.Tag = new ViewItem()
  27. {
  28. Id = "backward",
  29. };
  30. btnExit.Tag = new ViewItem()
  31. {
  32. Id = "exit",
  33. };
  34. btnForward.Tag = new ViewItem()
  35. {
  36. Id = "forward",
  37. };
  38. }
  39. public void CreateMenu(List<ViewItem> items)
  40. {
  41. double marginLeft = btnBackward.Margin.Left + btnBackward.Width + 50;
  42. foreach (ViewItem item in items)
  43. {
  44. Button btn = new Button();
  45. btn.Style = btnExit.Style;
  46. btn.Margin = new Thickness(marginLeft, btnExit.Margin.Top, 0, 0);
  47. btn.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  48. btn.VerticalAlignment = System.Windows.VerticalAlignment.Center;
  49. btn.Content = item.Name;
  50. btn.Tag = item;
  51. btn.Click += new RoutedEventHandler(btn_Click);
  52. marginLeft += (btn.Width + 50);
  53. gridContent.Children.Add(btn);
  54. }
  55. }
  56. void btn_Click(object sender, RoutedEventArgs e)
  57. {
  58. if (ButtonClicked != null)
  59. {
  60. ButtonClicked(((sender as Button).Tag as ViewItem).Id);
  61. }
  62. }
  63. public void SetSelection(string id)
  64. {
  65. ImageBrush NormalBrush = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Core;component/Resources/Main/主菜单按钮150.png", UriKind.Absolute)));
  66. ImageBrush SelectedBrush = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Core;component/Resources/Main/主菜单按钮_选中150.png", UriKind.Absolute)));
  67. foreach (var item in gridContent.Children)
  68. {
  69. Button btn = item as Button;
  70. if ((btn.Tag as ViewItem).Name == null)
  71. continue;
  72. btn.Background = ((btn.Tag as ViewItem).Id == id) ? SelectedBrush : NormalBrush;
  73. btn.Height = ((btn.Tag as ViewItem).Id == id) ? 45: 38;
  74. btn.Width = ((btn.Tag as ViewItem).Id == id) ? 160 : 145;
  75. }
  76. }
  77. public void Enable(string id, bool enable)
  78. {
  79. foreach (var item in gridContent.Children)
  80. {
  81. Button btn = item as Button;
  82. if ((btn.Tag as ViewItem).Name == null)
  83. continue;
  84. if ((btn.Tag as ViewItem).Id != id)
  85. continue;
  86. btn.Visibility = !enable ? Visibility.Hidden : Visibility.Visible;
  87. }
  88. }
  89. public void SetCulture(string culture)
  90. {
  91. foreach (var item in gridContent.Children)
  92. {
  93. Button btn = item as Button;
  94. ViewItem info = btn.Tag as ViewItem;
  95. if (info==null || info.Name==null || info.GlobalName==null || !info.GlobalName.ContainsKey(culture))
  96. continue;
  97. btn.Content = info.GlobalName[culture];
  98. }
  99. }
  100. }
  101. }