Beispiel #1
0
        /// <summary>
        /// 获取Mapping依赖属性值,若为null,则初始化为空集合
        /// </summary>
        /// <param name="obj">附加对象</param>
        /// <returns>返回Mapping依赖属性值</returns>
        internal static CommandEventCollection InternalGetMappingCollection(DependencyObject obj)
        {
            var map = obj.GetValue(MappingsProperty) as CommandEventCollection;

            if (map == null)//属性值为null,初始化新集合
            {
                map = new CommandEventCollection();
                SetMappings(obj, map);
            }
            return(map);
        }
Beispiel #2
0
        /// <summary>
        /// Mapping附加依赖属性值变更处理函数
        /// </summary>
        /// <param name="target">附加对象</param>
        /// <param name="e">信息参数</param>
        private static void OnMappingsChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue != null)
            {
                CommandEventCollection cec = e.OldValue as CommandEventCollection;
                if (cec != null)//解除命令与事件链接
                {
                    cec.Unsubscribe(target);
                }
            }

            if (e.NewValue != null)
            {
                CommandEventCollection cec = e.NewValue as CommandEventCollection;
                if (cec != null)//进行命令与事件链接
                {
                    cec.Subscribe(target);
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Mappings附加依赖属性设置方法
 /// </summary>
 /// <param name="obj">附加对象</param>
 /// <param name="value">设置值</param>
 public static void SetMappings(DependencyObject obj, CommandEventCollection value)
 {
     obj.SetValue(MappingsProperty, value);
 }