Common.cs 1.13 KB
Newer Older
1 2 3 4 5 6 7 8
using FLY.OBJComponents.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

潘栩锋's avatar
潘栩锋 committed
9
namespace FLY.Thick.Base.UI
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
{
    /// <summary>
    /// 公共类
    /// </summary>
    public static class Common
    {
        /// <summary>
        /// 绑定 Application.Current.Properties["WindowSize"] 到 BufferWindow.Size
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="createWindow"></param>
        public static void BindingWindowSize<T>(Func<int, BufferWindow<T>> createWindow)
        {
            int windowSize = 30;
            if (Application.Current.Properties["WindowSize"] is int)
                windowSize = (int)Application.Current.Properties["WindowSize"];
            var window = createWindow(windowSize);
            window.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "Size")
                {
                    var w = s as BufferWindow<T>;
                    Application.Current.Properties["WindowSize"] = w.Size;
                }
            };
        }
    }
}