| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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
- {
- /// <summary>
- /// VerticalLayout.xaml 的交互逻辑
- /// </summary>
- public partial class VerticalLayout : UserControl
- {
- public VerticalLayout()
- {
- LogInfoHelper.WriteInfo("VerticalLayout");
- InitializeComponent();
- MessengerHelper.DefaultRegister<string>(this, MessengerTokens.SaveLayout, (s) =>
- {
- var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
- ////保存布局
- if (homeView.IsTradeVisible)
- {
- SaveLayout();
- }
- });
- this.Loaded += VerticalLayout_Loaded;
- if (UserManager.IsAccountLogin)
- {
- this.Unloaded += VerticalLayout_Unloaded;
- }
- }
- /// <summary>
- /// 获取本地配置
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
- private void VerticalLayout_Loaded(object sender, RoutedEventArgs e)
- {
- var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
- 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();
- }
- /// <summary>
- /// 保存配置
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
- private void VerticalLayout_Unloaded(object sender, RoutedEventArgs e)
- {
- var homeView = SimpleIoc.Default.GetInstance<HomeViewModel>();
- if (UserManager.IsAccountLogin && homeView.IsSaveLayout)
- {
- ////保存布局
- SaveLayout();
- }
- MessengerHelper.DefaultUnregister(this);
- }
- /// <summary>
- /// 保存布局
- /// </summary>
- 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
- });
- }
- }
- }
|