using FLY.OBJComponents.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ThickTcpUiInWindow
{
    /// <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;
                }
            };
        }
    }
}
