BottomView.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. private int ButtonMarginLeft = 60;
  23. Size ButtonSizeSelected = new Size(160, 45);
  24. Size ButtonSizeUnselected = new Size(145, 38);
  25. public event Action<string> ButtonClicked;
  26. public BottomView()
  27. {
  28. InitializeComponent();
  29. //btnBackward.Tag = new ViewItem()
  30. //{
  31. // Id = "backward",
  32. //};
  33. btnExit.Tag = new ViewItem()
  34. {
  35. Id = "exit",
  36. };
  37. //btnForward.Tag = new ViewItem()
  38. //{
  39. // Id = "forward",
  40. //};
  41. }
  42. public void CreateMenu(List<ViewItem> items)
  43. {
  44. //double marginLeft = btnBackward.Margin.Left + btnBackward.Width + 50;
  45. double marginLeft = ButtonSizeUnselected.Width;
  46. foreach (ViewItem item in items)
  47. {
  48. Button btn = new Button();
  49. btn.Style = Resources["navButton"] as Style;
  50. btn.Margin = new Thickness(marginLeft, btnExit.Margin.Top, 0, 10);
  51. btn.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  52. btn.VerticalAlignment = System.Windows.VerticalAlignment.Center;
  53. btn.Content = item.Name;
  54. btn.Tag = item;
  55. btn.Click += new RoutedEventHandler(btn_Click);
  56. marginLeft += (btn.Width + ButtonMarginLeft);
  57. gridContent.Children.Add(btn);
  58. }
  59. }
  60. void btn_Click(object sender, RoutedEventArgs e)
  61. {
  62. if (ButtonClicked != null)
  63. {
  64. ButtonClicked(((sender as Button).Tag as ViewItem).Id);
  65. }
  66. }
  67. public void SetSelection(string id)
  68. {
  69. ImageBrush NormalBrush = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Main/主菜单按钮150.png", UriKind.Absolute)));
  70. ImageBrush SelectedBrush = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Main/主菜单按钮_选中150.png", UriKind.Absolute)));
  71. foreach (var item in gridContent.Children)
  72. {
  73. Button btn = item as Button;
  74. if ((btn==null) || ((btn.Tag as ViewItem).Name == null))
  75. continue;
  76. btn.Background = ((btn.Tag as ViewItem).Id == id) ? SelectedBrush : NormalBrush;
  77. btn.Height = ((btn.Tag as ViewItem).Id == id) ? 45: 38;
  78. btn.Width = ((btn.Tag as ViewItem).Id == id) ? 160 : 145;
  79. }
  80. }
  81. public void Enable(string id, bool enable)
  82. {
  83. foreach (var item in gridContent.Children)
  84. {
  85. Button btn = item as Button;
  86. if (btn == null)
  87. continue;
  88. if ((btn.Tag as ViewItem).Name == null)
  89. continue;
  90. if ((btn.Tag as ViewItem).Id != id)
  91. continue;
  92. btn.Visibility = !enable ? Visibility.Hidden : Visibility.Visible;
  93. }
  94. }
  95. public void SetCulture(string culture)
  96. {
  97. foreach (var item in gridContent.Children)
  98. {
  99. Button btn = item as Button;
  100. if (btn == null)
  101. continue;
  102. ViewItem info = btn.Tag as ViewItem;
  103. if (info==null || info.Name==null || info.GlobalName==null || !info.GlobalName.ContainsKey(culture))
  104. continue;
  105. btn.Content = info.GlobalName[culture];
  106. }
  107. }
  108. }
  109. }