private static Dictionary <string, BLE_PropertyDataModel> CreatePropertiesDictionary(IReadOnlyDictionary <string, object> propertyDict)
        {
            Dictionary <string, BLE_PropertyDataModel> properties = new Dictionary <string, BLE_PropertyDataModel>();

            if (propertyDict != null)
            {
                foreach (var p in propertyDict)
                {
                    BLE_PropertyDataModel model = new BLE_PropertyDataModel()
                    {
                        Key    = p.Key,
                        Target = GetPropertyTarget(p.Key),
                    };
                    SetPropertyValue(p.Value, model);
                    if (!properties.ContainsKey(model.Key))
                    {
                        properties.Add(model.Key, model);
                    }
                    else
                    {
                        log.Error(9999, "CreatePropertiesDictionary", () => string.Format("Duplicate property key '{0}'", model.Key));
                    }
                }
            }
            return(properties);
        }
예제 #2
0
        /// <summary>
        /// Call in MyWindowStyle styled Window OnApplyTemplate to bind drag and move
        /// </summary>
        /// <remarks>Call in the overriden OnApplyTemplate function</remarks>
        /// <param name="win">The window calling this function</param>
        public static void BindMouseDownToCustomTitleBar(this Window win)
        {
            try {
                if (win != null)
                {
                    Border b = win.Template.FindName("brdTitle", win) as Border;
                    if (b != null)
                    {
                        b.MouseDown += (sender, args) => {
                            WrapErr.ToErrReport(9999, "Drag when mouse not down", () => {
                                if (win.WindowState == WindowState.Maximized)
                                {
                                    // Dislodge it from maximized state to move
                                    win.WindowState = WindowState.Normal;

                                    // Center the window on the click point
                                    Point p  = args.GetPosition(win);
                                    win.Top  = p.Y - 15; // Middle of top bar
                                    win.Left = p.X - (win.Width / 2.0);
                                    win.DragMove();
                                }
                                else
                                {
                                    win.DragMove();
                                }
                            });
                        };
                    }
                    else
                    {
                        LOG.Error(9999, "Could not find PART_topBar - are you sure you have style set to MyWindowStyle?");
                    }
                }
            }
            catch (Exception e) {
                LOG.Exception(9999, "BindMouseDownToCustomTitleBar", "", e);
            }
        }