123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using FWindSoft.Data;
- using FWindSoft.Wpf.Controls;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace FWindSoft.Wpf.Common
- {
- public class ResultMessage
- {
- #region 窗体附加参数维护
- public static readonly DependencyProperty ResultProperty = DependencyProperty.RegisterAttached("Result",
- typeof(DataWrapper), typeof(ResultMessage), new PropertyMetadata(null, null));
- [AttachedPropertyBrowsableForType(typeof(UIElement))]
- public static DataWrapper GetResult(DependencyObject obj)
- {
- return obj.GetValue(ResultProperty) as DataWrapper;
- }
- [AttachedPropertyBrowsableForType(typeof(UIElement))]
- public static void SetResult(DependencyObject obj, DataWrapper value)
- {
- obj.SetValue(ResultProperty, value);
- }
- static ResultMessage()
- {
- }
- #endregion
-
- }
- public static class ResultMessageExtension
- {
- public static DataWrapper GetResult(this UIElement baseWindow)
- {
- return ResultMessage.GetResult(baseWindow);
- }
- public static void SetResult(this UIElement baseWindow,DataWrapper wrapper)
- {
- ResultMessage.SetResult(baseWindow, wrapper);
- }
- /// <summary>
- /// 获取关联真实值
- /// </summary>
- /// <param name="baseWindow"></param>
- /// <returns></returns>
- public static object GetRealResult(this UIElement baseWindow)
- {
- var dataWrapper= ResultMessage.GetResult(baseWindow) as DataWrapper;
- if (dataWrapper == null)
- return null;
- return dataWrapper.Parameter;
- }
- public static T GetRealResult<T>(this UIElement baseWindow)
- {
- var dataWrapper = ResultMessage.GetResult(baseWindow) as DataWrapper;
- if (dataWrapper == null)
- return default(T);
- return dataWrapper.GetValue<T>();
- }
- /// <summary>
- /// 设置关联真实值
- /// </summary>
- /// <param name="baseWindow"></param>
- /// <param name="realValue"></param>
- public static void SetRealResult(this UIElement baseWindow, object realValue)
- {
- var dataWrapper = new DataWrapper(realValue);
- ResultMessage.SetResult(baseWindow, dataWrapper);
- }
- public static void SetRealResult<T>(this UIElement baseWindow, T realValue)
- {
- SetRealResult(baseWindow, (object)realValue);
- }
- }
- }
|