using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model.Config; using Muchinfo.MTPClient.Infrastructure.Utilities; using System.Windows; using System.Windows.Controls; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.UI.ViewModels; namespace Muchinfo.MTPClient.UI.Views { /// /// VerticalLayout.xaml 的交互逻辑 /// public partial class VerticalLayout : UserControl { public VerticalLayout() { LogInfoHelper.WriteInfo("VerticalLayout"); InitializeComponent(); MessengerHelper.DefaultRegister(this, MessengerTokens.SaveLayout, (s) => { var homeView = SimpleIoc.Default.GetInstance(); ////保存布局 if (homeView.IsTradeVisible) { SaveLayout(); } }); this.Loaded += VerticalLayout_Loaded; if (UserManager.IsAccountLogin) { this.Unloaded += VerticalLayout_Unloaded; } } /// /// 获取本地配置 /// /// The source of the event. /// The instance containing the event data. private void VerticalLayout_Loaded(object sender, RoutedEventArgs e) { var homeView = SimpleIoc.Default.GetInstance(); if (UserManager.IsAccountLogin && homeView.IsTradeVisible) { var userLayout = UserManager.GetLayoutStyle(LayoutStyle.Vertical); VerticalLayoutGrid.RowDefinitions[3] = new RowDefinition() { Height = new GridLength(userLayout.QuoteGridRowLengthValue, userLayout.QuoteGridRowLengthUnitType), // MinHeight = userLayout.QuoteGridRowMinHeight }; VerticalLayoutGrid.RowDefinitions[4] = new RowDefinition() { Height = new GridLength(userLayout.QueryGridRowLengthValue, userLayout.QueryGridRowLengthUnitType), // MinHeight = userLayout.QueryGridRowMinHeight }; homeView.IsSaveLayout = true; } else { VerticalLayoutGrid.RowDefinitions[4] = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto), }; homeView.IsSaveLayout = false; } ////重新布局 VerticalLayoutGrid.InvalidateMeasure(); } /// /// 保存配置 /// /// The source of the event. /// The instance containing the event data. private void VerticalLayout_Unloaded(object sender, RoutedEventArgs e) { var homeView = SimpleIoc.Default.GetInstance(); if (UserManager.IsAccountLogin && homeView.IsSaveLayout) { ////保存布局 SaveLayout(); } MessengerHelper.DefaultUnregister(this); } /// /// 保存布局 /// private void SaveLayout() { UserManager.SaveLayoutStyle(LayoutStyle.Vertical, new UserLayout() { QuoteGridRowLengthValue = VerticalLayoutGrid.RowDefinitions[3].Height.Value, QuoteGridRowLengthUnitType = VerticalLayoutGrid.RowDefinitions[3].Height.GridUnitType, QuoteGridRowMinHeight = VerticalLayoutGrid.RowDefinitions[3].MinHeight, QueryGridRowLengthValue = VerticalLayoutGrid.RowDefinitions[4].Height.Value, QueryGridRowLengthUnitType = VerticalLayoutGrid.RowDefinitions[4].Height.GridUnitType, QueryGridRowMinHeight = VerticalLayoutGrid.RowDefinitions[4].MinHeight }); } } }