PageManager.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.Controls;
  7. namespace NEIntelligentControl2.Models.Pages
  8. {
  9. /// <summary>
  10. /// 页面管理
  11. /// </summary>
  12. public class PageManager : IPageAction
  13. {
  14. /// <summary>
  15. /// 获取页面
  16. /// </summary>
  17. /// <param name="name">页面名称</param>
  18. /// <returns>页面</returns>
  19. public Page this[string name]
  20. {
  21. get
  22. {
  23. var tp = Type.GetType($"NEIntelligentControl2.Pages.{name}");
  24. if (tp == null)
  25. {
  26. throw new Exception($"未发现{name}页面!");
  27. }
  28. var page = App.ServiceProvider.GetService(tp) as Page;
  29. /*
  30. * 如果页面未注册,请在App类里的ConfigureServices方法中注册这个页面(将页面添加到依赖注入框架中)
  31. */
  32. if (page == null)
  33. {
  34. throw new Exception($"{name}页面未注册!");
  35. }
  36. return page;
  37. }
  38. }
  39. }
  40. }