VerticalLayout.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using GalaSoft.MvvmLight.Ioc;
  2. using Muchinfo.MTPClient.Data.Enums;
  3. using Muchinfo.MTPClient.Data.Model.Config;
  4. using Muchinfo.MTPClient.Infrastructure.Utilities;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using Muchinfo.MTPClient.Infrastructure.Helpers;
  8. using Muchinfo.MTPClient.UI.ViewModels;
  9. namespace Muchinfo.MTPClient.UI.Views
  10. {
  11. /// <summary>
  12. /// VerticalLayout.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class VerticalLayout : UserControl
  15. {
  16. public VerticalLayout()
  17. {
  18. LogInfoHelper.WriteInfo("VerticalLayout");
  19. InitializeComponent();
  20. MessengerHelper.DefaultRegister<string>(this, MessengerTokens.SaveLayout, (s) =>
  21. {
  22. var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
  23. ////保存布局
  24. if (homeView.IsTradeVisible)
  25. {
  26. SaveLayout();
  27. }
  28. });
  29. this.Loaded += VerticalLayout_Loaded;
  30. if (UserManager.IsAccountLogin)
  31. {
  32. this.Unloaded += VerticalLayout_Unloaded;
  33. }
  34. }
  35. /// <summary>
  36. /// 获取本地配置
  37. /// </summary>
  38. /// <param name="sender">The source of the event.</param>
  39. /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
  40. private void VerticalLayout_Loaded(object sender, RoutedEventArgs e)
  41. {
  42. var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
  43. if (UserManager.IsAccountLogin && homeView.IsTradeVisible)
  44. {
  45. var userLayout = UserManager.GetLayoutStyle(LayoutStyle.Vertical);
  46. VerticalLayoutGrid.RowDefinitions[3] = new RowDefinition()
  47. {
  48. Height = new GridLength(userLayout.QuoteGridRowLengthValue, userLayout.QuoteGridRowLengthUnitType),
  49. // MinHeight = userLayout.QuoteGridRowMinHeight
  50. };
  51. VerticalLayoutGrid.RowDefinitions[4] = new RowDefinition()
  52. {
  53. Height = new GridLength(userLayout.QueryGridRowLengthValue, userLayout.QueryGridRowLengthUnitType),
  54. // MinHeight = userLayout.QueryGridRowMinHeight
  55. };
  56. homeView.IsSaveLayout = true;
  57. }
  58. else
  59. {
  60. VerticalLayoutGrid.RowDefinitions[4] = new RowDefinition()
  61. {
  62. Height = new GridLength(1, GridUnitType.Auto),
  63. };
  64. homeView.IsSaveLayout = false;
  65. }
  66. ////重新布局
  67. VerticalLayoutGrid.InvalidateMeasure();
  68. }
  69. /// <summary>
  70. /// 保存配置
  71. /// </summary>
  72. /// <param name="sender">The source of the event.</param>
  73. /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
  74. private void VerticalLayout_Unloaded(object sender, RoutedEventArgs e)
  75. {
  76. var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
  77. if (UserManager.IsAccountLogin && homeView.IsSaveLayout)
  78. {
  79. ////保存布局
  80. SaveLayout();
  81. }
  82. MessengerHelper.DefaultUnregister(this);
  83. }
  84. /// <summary>
  85. /// 保存布局
  86. /// </summary>
  87. private void SaveLayout()
  88. {
  89. UserManager.SaveLayoutStyle(LayoutStyle.Vertical, new UserLayout()
  90. {
  91. QuoteGridRowLengthValue = VerticalLayoutGrid.RowDefinitions[3].Height.Value,
  92. QuoteGridRowLengthUnitType = VerticalLayoutGrid.RowDefinitions[3].Height.GridUnitType,
  93. QuoteGridRowMinHeight = VerticalLayoutGrid.RowDefinitions[3].MinHeight,
  94. QueryGridRowLengthValue = VerticalLayoutGrid.RowDefinitions[4].Height.Value,
  95. QueryGridRowLengthUnitType = VerticalLayoutGrid.RowDefinitions[4].Height.GridUnitType,
  96. QueryGridRowMinHeight = VerticalLayoutGrid.RowDefinitions[4].MinHeight
  97. });
  98. }
  99. }
  100. }