Exemple #1
0
        internal static void ResetState(FrameworkElement control, Stream stream)
        {
            States        states = GetCurrentStates(stream);
            StatesControl ctrl   = states.GetControl(control.Name);

            if (ctrl != null)
            {
                states.Controls.Remove(ctrl);
                SaveState(control, stream);
            }
        }
Exemple #2
0
        internal static bool LoadState(FrameworkElement control, Stream stream)
        {
            States        states = GetCurrentStates(stream);
            string        pId    = control.Name;
            StatesControl ctrl   = states.GetControl(pId);

            if (ctrl != null)
            {
                MinimizeHelper minimizeHelper = ((IMinimizeHelped)control).ResizeHelper;

                control.Visibility = ctrl.Visibility;

                control.Width = ctrl.Width;
                minimizeHelper.IsMinimized   = ctrl.Minimized;
                minimizeHelper.ExpandedWidth = ctrl.ExpandedWidth;
                minimizeHelper.ExpandedDelta = ctrl.ExpandedDelta;
                minimizeHelper.ResetMinizedSize();

                if (control is NavigationPane)
                {
                    NavigationPane pane = control as NavigationPane;

                    pane.LargeItems = ctrl.Items.LargeItems;

                    IEnumerable <NavigationPaneItem> items = pane.Items.OfType <NavigationPaneItem>();
                    // if Linq were a girl, I should absolutely marry her
                    var sorted =
                        from data in
                        (
                            from item in items
                            join sItem in ctrl.Items.Items on item.Name equals sItem.Identifier into itemStates
                            from itemState in itemStates.DefaultIfEmpty()
                            select new { Index = itemState == null ? NavigationPanePanel.GetAbosluteIndex(item) : itemState.Order - 0.5, Exluded = itemState == null ? false : itemState.Excluded, Item = item }
                        )
                        orderby data.Index
                        select data;

                    List <NavigationPaneItem> orderdItems = new List <NavigationPaneItem>();
                    foreach (var item in sorted)
                    {
                        NavigationPane.SetIsItemExcluded(item.Item, item.Exluded);
                        orderdItems.Add(item.Item);
                    }
                    pane.Items.Clear();
                    foreach (NavigationPaneItem item in orderdItems)
                    {
                        pane.Items.Add(item);
                    }
                }
                return(true);
            }
            return(false);
        }
        public StatesControl GetControl(string id, bool create = false)
        {
            IEnumerable<StatesControl> result = Controls.Where(st => st.Identifier == id);
               if (result.Count() > 0)
            return result.First();

               if (create)
               {
            StatesControl control = new StatesControl();
            control.Identifier = id;
            Controls.Add(control);
            return control;
               }
               return null;
        }
Exemple #4
0
        public static void SaveState(FrameworkElement control, Stream stream)
        {
            if (string.IsNullOrEmpty(control.Name))
            {
                throw new UniqueIdentierNotSet();
            }

            States states = GetCurrentStates(stream);

            XmlSerializer s = new XmlSerializer(typeof(States));

            string        pId  = control.Name;
            StatesControl ctrl = states.GetControl(pId, true);

            //we should use the MinizeHelper to get the correct size if the control io minimized
            MinimizeHelper minimizeHelper = ((IMinimizeHelped)control).ResizeHelper;

            ctrl.ExpandedWidth = minimizeHelper.ExpandedWidth;
            ctrl.ExpandedDelta = minimizeHelper.ExpandedDelta;

            ctrl.ActualWidth = control.ActualWidth;
            ctrl.Width       = control.Width;
            ctrl.Minimized   = minimizeHelper.IsMinimized;

            ctrl.Visibility = control.Visibility;

            if (control is NavigationPane)
            {
                NavigationPane pane = control as NavigationPane;

                if (ctrl.Items == null)
                {
                    ctrl.Items = new StatesControlItems();
                }

                ctrl.Items.LargeItems = pane.LargeItems;
                ctrl.Items.Items.Clear();
                for (int j = 0; j < pane.Items.Count; j++)
                {
                    NavigationPaneItem item = (NavigationPaneItem)pane.Items[j];
                    if (!string.IsNullOrEmpty(item.Name))
                    {
                        ctrl.Items.Items.Add(new StatesControlItemsItem(item.Name, NavigationPane.GetIsItemExcluded(item), j));
                    }
                }
            }
            s.Serialize(stream, states);
        }
Exemple #5
0
        public StatesControl GetControl(string id, bool create = false)
        {
            IEnumerable <StatesControl> result = Controls.Where(st => st.Identifier == id);

            if (result.Count() > 0)
            {
                return(result.First());
            }

            if (create)
            {
                StatesControl control = new StatesControl();
                control.Identifier = id;
                Controls.Add(control);
                return(control);
            }
            return(null);
        }