CenterView.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. using System.Reflection;
  15. using Aitex.Core.RT.Log;
  16. using MECF.Framework.UI.Core.Applications;
  17. using Autofac;
  18. namespace Aitex.Core.UI.View.Frame
  19. {
  20. /// <summary>
  21. /// Interaction logic for CenterView.xaml
  22. /// </summary>
  23. public partial class CenterView : UserControl
  24. {
  25. Dictionary<string, CenterTabView> _views = new Dictionary<string,CenterTabView>();
  26. public CenterView()
  27. {
  28. InitializeComponent();
  29. }
  30. public void CreateView(List<ViewItem> views )
  31. {
  32. foreach (ViewItem item in views)
  33. {
  34. if (item.SubView == null || item.SubView.Count == 0)
  35. continue;
  36. CenterTabView tab = new CenterTabView();
  37. tab.Tag = item;
  38. foreach (ViewItem subItem in item.SubView)
  39. {
  40. Type t = Assembly.Load(subItem.AssemblyName).GetType(subItem.ViewClass);
  41. if (t == null)
  42. throw new ApplicationException(string.Format("The ui layout config file not valid, can not find {0} at assembly {1}", subItem.ViewClass, subItem.AssemblyName));
  43. UserControl uc;
  44. try
  45. {
  46. using (var scope = UiApplication.Instance.Container.BeginLifetimeScope())
  47. {
  48. if (scope.TryResolve(t, out var target))
  49. {
  50. uc = target as UserControl;
  51. }
  52. else
  53. {
  54. uc = (UserControl)Activator.CreateInstance(t);
  55. }
  56. }
  57. }
  58. catch (Exception ex)
  59. {
  60. LOG.Write(ex);
  61. throw new ApplicationException(string.Format("Failed to initialize UI window {0}, {1}", subItem.ViewClass, ex.Message));
  62. }
  63. tab.Add(subItem, uc);
  64. }
  65. _views[item.Id] = tab;
  66. }
  67. }
  68. public void SetSelection(string id)
  69. {
  70. if (!_views.ContainsKey(id))
  71. return;
  72. _views[id].Height = this.Height ;
  73. gridContent.Children.Clear();
  74. gridContent.Children.Add(_views[id]);
  75. }
  76. public string GetCurrentViewName(string culture)
  77. {
  78. if (gridContent.Children.Count == 0)
  79. return string.Empty;
  80. ViewItem info = (gridContent.Children[0] as CenterTabView).Tag as ViewItem;
  81. if (!string.IsNullOrEmpty(culture) && info.GlobalName.ContainsKey(culture))
  82. return info.GlobalName[culture];
  83. return info.Name;
  84. }
  85. public UserControl GetView(string id)
  86. {
  87. foreach (var item in _views)
  88. {
  89. if (item.Value.FindView(id) != null)
  90. return item.Value.FindView(id);
  91. }
  92. return null;
  93. }
  94. public TabItem GetTab(string id)
  95. {
  96. foreach (var item in _views)
  97. {
  98. if (item.Value.FindTab(id) != null)
  99. return item.Value.FindTab(id);
  100. }
  101. return null;
  102. }
  103. public void SetCulture(string culture)
  104. {
  105. foreach (var item in _views)
  106. {
  107. item.Value.SetCulture(culture);
  108. }
  109. }
  110. }
  111. }