예제 #1
0
        private MenuItem MenuItemFromNavigationPaneItem(NavigationPaneItem item, bool isHiddenItem)
        {
            MenuItem menuItem = new MenuItem();

            menuItem.IsCheckable = true;

            Binding b = new Binding();

            b.Source = item;
            if (isHiddenItem)
            {
                b.Path = new PropertyPath(Selector.IsSelectedProperty);
            }
            else
            {
                b.Path      = new PropertyPath(NavigationPane.IsItemExcludedProperty);
                b.Converter = new BooleanNegateConverter();
            }
            b.Mode = BindingMode.TwoWay;

            menuItem.SetBinding(MenuItem.IsCheckedProperty, b);

            if (item.ImageSmall != null)
            {
                Image image = new Image();
                image.Width   = 16;
                image.Height  = 16;
                image.Source  = item.ImageSmall;
                menuItem.Icon = image;
            }
            menuItem.Header = XamlHelper.CloneUsingXaml(item.Header, true);

            return(menuItem);
        }
예제 #2
0
        private void CheckAddRemoveItems()
        {
            if (_navigationPane == null)
            {
                return;
            }

            foreach (object obj in _navigationPane.Items)
            {
                NavigationPaneItem item = obj as NavigationPaneItem;
                if (item == null)
                {
                    item = _navigationPane.ItemContainerGenerator.ContainerFromItem(obj) as NavigationPaneItem;
                }

                if (item == null)
                {
                    continue;
                }

                if (!_subItems.Contains(item))
                {
                    MenuItem menuItem = MenuItemFromNavigationPaneItem(item, false);
                    _subItems.Add(item, menuItem);
                    Items.Add(menuItem);
                }
            }
            CleanSubItems();
        }
예제 #3
0
        private static object CoerceImage(DependencyObject d, object value)
        {
            NavigationPaneItem item = d as NavigationPaneItem;

            item.CoerceValue(ImageSmallProperty);
            if (item.ImageSmall == null)
            {
                item.ImageSmall = (ImageSource)value;
            }

            return(value);
        }
예제 #4
0
 private void ResetItems()
 {
     Items.Clear();
     for (int j = 0; j < navigationPane.Items.Count; j++)
     {
         NavigationPaneItem item = navigationPane.Items[j] is NavigationPaneItem ? navigationPane.Items[j] as NavigationPaneItem:
                                   navigationPane.ItemContainerGenerator.ContainerFromIndex(j) as NavigationPaneItem;
         if (item != null)
         {
             Items.Add(new NavigationPaneOptionsData(item, XamlHelper.CloneUsingXaml(item.Header, true), !NavigationPane.GetIsItemExcluded(item)));
         }
     }
 }
예제 #5
0
        private static object CoerceButtonToolTip(DependencyObject d, object value)
        {
            NavigationPaneItem item    = d as NavigationPaneItem;
            object             toolTip = item.ButtonToolTip == null ? item.Header : item.ButtonToolTip;

            if (toolTip is string && item.ShowGesture)
            {
                return(string.Format("{0} ({1})", toolTip, item.Gesture));
            }
            else
            {
                return(toolTip);
            }
        }
예제 #6
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);
        }
예제 #7
0
        private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            NavigationPaneItem item = d as NavigationPaneItem;

            if ((bool)e.NewValue)
            {
                NavigationPane nav = item.navigationPane; // item.Parent as NavigationPane;
                if (nav != null)
                {
                    NavigationPaneItem selItem = (nav.SelectedItem is NavigationPaneItem ? nav.SelectedItem :
                                                  nav.ItemContainerGenerator.ContainerFromItem(nav.SelectedItem)) as NavigationPaneItem;
                    if (selItem != null && selItem != item)
                    {
                        (selItem as NavigationPaneItem).IsSelected = false;
                    }
                }
                item.ChangeSelected(true);
            }
            else
            {
                item.ChangeSelected(false);
            }
        }
예제 #8
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            CreateItemsHeaders();

            if (item is HeaderedContentControl)
            {
                itemsHeaders.Add(new NavigationPaneExpanderItemsHeader(item));
            }

            base.PrepareContainerForItemOverride(element, item);

            if (!(item is FrameworkElement))
            {
                NavigationPaneItem i = element as NavigationPaneItem;
                if (i != null)
                {
                    i.ContentTemplate         = ItemTemplate;
                    i.ContentTemplateSelector = ItemTemplateSelector;
                    i.ContentStringFormat     = ItemStringFormat;
                }

                itemsHeaders.Add(new NavigationPaneExpanderItemsHeader(item));
            }

            Binding b = new Binding();

            b.Source = item;
            if (item is FrameworkElement)
            {
                b.Path = new PropertyPath(CanResizeProperty);
            }
            else
            {
                b.Path = new PropertyPath("CanResize");
            }
            (element as FrameworkElement).SetBinding(CanResizeProperty, b);
        }
예제 #9
0
        protected override Size MeasureOverride(Size availableSize)
        {
            Size desiredSize = new Size();
            UIElementCollection     children  = InternalChildren;
            IItemContainerGenerator generator = ItemContainerGenerator;

            int itemsCount = 0;

            if (generator != null)
            {
                int StartItemIndex = navigationPane.GetFirstItemIndex(DisplayType);
                if (StartItemIndex > -1)
                {
                    int maxItems = DisplayType == NavigationPaneItemDisplayType.Large ? navigationPane.LargeItems : int.MaxValue;
                    GeneratorPosition startPos = new GeneratorPosition(-1, StartItemIndex + 1);

                    using (generator.StartAt(startPos, GeneratorDirection.Forward, true))
                    {
                        bool sizeExceeded = false;

                        bool      newlyRealized;
                        UIElement child = null;

                        // temp fix for {Disconnected Item}
                        // needs more inspecting and documentation to fix it correctly !!
                        // but this for now seems to work... strange items present ??
                        // remove them, NOW !!!!!
                        //for (int j = children.Count - 1; j > -1; j--)
                        //{
                        //UIElement item = children[j];
                        //object o = navigationPane.ItemContainerGenerator.ItemFromContainer(item);
                        //if (o == DependencyProperty.UnsetValue)
                        // RemoveInternalChild(item);
                        //}

                        while (!sizeExceeded && (itemsCount < maxItems) && (child = generator.GenerateNext(out newlyRealized) as UIElement) != null)
                        {
                            bool isExcluded = NavigationPane.GetIsItemExcluded(child);
                            if (!isExcluded)
                            {
                                if (newlyRealized || !children.Contains(child))
                                {
                                    int absoluteIndex = StartItemIndex + itemsCount;
                                    int index         = GetInsertIndex(absoluteIndex);

                                    if (absoluteIndex < 9 && navigationPane.ItemsKeyAuto)
                                    {
                                        NavigationPaneItem f = child as NavigationPaneItem;
                                        {
                                            Window w = Window.GetWindow(child);
                                            if (w != null)
                                            {
                                                KeyBinding binding = f.keyBinding;
                                                if (binding != null)
                                                {
                                                    w.InputBindings.Remove(binding);
                                                }

                                                f.keyBinding = new KeyBinding(NavigationPane.SelectItemCommand, Key.D1 + absoluteIndex, navigationPane.ItemsKeyModifiers);
                                                f.keyBinding.CommandParameter = child;
                                                f.keyBinding.CommandTarget    = navigationPane;
                                                w.InputBindings.Add(f.keyBinding);

                                                if (f != null)
                                                {
                                                    f.Gesture = (f.keyBinding.Gesture as KeyGesture).GetDisplayStringForCulture(CultureInfo.CurrentCulture);
                                                }
                                            }
                                        }
                                    }
                                    SetActivePanel(child, this);
                                    SetAbosluteIndex(child, absoluteIndex);
                                    SetItemDisplayType(child, DisplayType);

                                    if (newlyRealized)
                                    {
                                        generator.PrepareItemContainer(child);
                                    }

                                    InsertInternalChild(index, child);
                                }

                                #region measurament algoritm
                                Size childSize = new Size();
                                if (Orientation == Orientation.Vertical)
                                {
                                    childSize = new Size(availableSize.Width, double.PositiveInfinity);
                                }
                                else
                                {
                                    childSize = new Size(double.PositiveInfinity, availableSize.Height);
                                }

                                child.Measure(childSize);

                                if (Orientation == Orientation.Vertical)
                                {
                                    sizeExceeded = desiredSize.Height + child.DesiredSize.Height > availableSize.Height;
                                    if (!sizeExceeded)
                                    {
                                        desiredSize.Width   = Math.Max(desiredSize.Width, child.DesiredSize.Width);
                                        desiredSize.Height += child.DesiredSize.Height;
                                    }
                                }
                                else
                                {
                                    sizeExceeded = desiredSize.Width + child.DesiredSize.Width > availableSize.Width;
                                    if (!sizeExceeded)
                                    {
                                        desiredSize.Width += child.DesiredSize.Width;
                                        desiredSize.Height = Math.Max(desiredSize.Height, child.DesiredSize.Height);
                                    }
                                }
                                #endregion

                                if (!sizeExceeded)
                                {
                                    itemsCount++;
                                }
                            }
                            else
                            {
                                RemoveInternalChild(child);
                            }
                        }
                    }
                    CleanUpItems(StartItemIndex, itemsCount);
                }
            }

            if (DisplayType == NavigationPaneItemDisplayType.Small)
            {
                navigationPane.SmallItems = itemsCount;
            }
            return(desiredSize);
        }
예제 #10
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // MessageBox.Show(this.navigationPane.SelectedItemSubItems.Count().ToString());
            NavigationPaneItem item = new NavigationPaneItem();
            item.Header = newItemName.Text;
            item.Content = newItemContents.Text;
            StackPanel sp = new StackPanel();
            item.Content = sp;
            item.SubItems = new System.Collections.ObjectModel.ObservableCollection<NavigationPaneButton>();
            NavigationPaneButton btn = new NavigationPaneButton();
            btn.Content = "123";
            btn.Name = "实物";
            btn.Click += new RoutedEventHandler(NavPaneButton_Click);
            //item.SubItems.Insert(0, btn);
            sp.Children.Add(btn);
            btn.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            NavigationPaneButton btn1 = new NavigationPaneButton();
            btn1.Content = "1232";
            btn1.Name = "成果";
            btn1.Click += new RoutedEventHandler(NavPaneButton_Click);
            //item.SubItems.Insert(0, btn);
            sp.Children.Add(btn1);
            btn.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;

            item.Image = new BitmapImage(new Uri(@"pack://application:,,,/NavigationPaneDemo;component/Resources/folderopen.ico"));
            navigationPane.Items.Add(item);
            item.IsExcluded = newItemExcluded.IsChecked.Value;
        }
예제 #11
0
        private MenuItem MenuItemFromNavigationPaneItem(NavigationPaneItem item, bool isHiddenItem)
        {
            MenuItem menuItem = new MenuItem();

               menuItem.IsCheckable = true;

               Binding b = new Binding();
               b.Source = item;
               if (isHiddenItem)
            b.Path = new PropertyPath(Selector.IsSelectedProperty);
               else
               {
            b.Path = new PropertyPath(NavigationPane.IsItemExcludedProperty);
            b.Converter = new BooleanNegateConverter();
               }
               b.Mode = BindingMode.TwoWay;

               menuItem.SetBinding(MenuItem.IsCheckedProperty, b);

               if (item.ImageSmall != null)
               {
            Image image = new Image();
            image.Width = 16;
            image.Height = 16;
            image.Source = item.ImageSmall;
            menuItem.Icon = image;
               }
               menuItem.Header = XamlHelper.CloneUsingXaml(item.Header, true);

               return menuItem;
        }
예제 #12
0
        private void CheckHiddenItems()
        {
            if (_contextMenu == null)
            {
                return;
            }

            int startIndex = _contextMenu.Items.IndexOf(this);
            int index      = startIndex - _subItems.Count;

            for (int firstHidden = _navigationPane.GetFirstItemIndex(NavigationPaneItemDisplayType.Undefined);
                 firstHidden != -1 && firstHidden < _navigationPane.Items.Count; firstHidden++)
            {
                NavigationPaneItem item = _navigationPane.Items[firstHidden] as NavigationPaneItem;
                if (item != null && !NavigationPane.GetIsItemExcluded(item))
                {
                    index++;
                    if (!_subItems.Contains(item))
                    {
                        MenuItem menuItem = MenuItemFromNavigationPaneItem(item, true);
                        _subItems.Add(item, menuItem);
                        _contextMenu.Items.Insert(index, menuItem);
                    }
                }
            }
            CleanSubItems();

            bool addSeparator = (_subItems.Count > 0);

            if (addSeparator && Separator == ConfigureMenuSeparator.Top || Separator == ConfigureMenuSeparator.Both)
            {
                if (_separatorTop == null)
                {
                    _separatorTop = new Separator();
                }
                if (!_contextMenu.Items.Contains(_separatorTop))
                {
                    _contextMenu.Items.Insert(startIndex, _separatorTop);
                }
            }
            else if (_contextMenu.Items.Contains(_separatorTop))
            {
                _contextMenu.Items.Remove(_separatorTop);
            }

            if (addSeparator && Separator == ConfigureMenuSeparator.Bottom || Separator == ConfigureMenuSeparator.Both)
            {
                if (_separatorBottom == null)
                {
                    _separatorBottom = new Separator();
                }
                if (!_contextMenu.Items.Contains(_separatorBottom))
                {
                    _contextMenu.Items.Insert(index + 1, _separatorBottom);
                }
            }
            else if (_contextMenu.Items.Contains(_separatorBottom))
            {
                _contextMenu.Items.Remove(_separatorBottom);
            }
        }
예제 #13
0
        // Command dependency property change callback.
        private static void CommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            NavigationPaneItem item = (NavigationPaneItem)d;

            item.HookUpCommand((ICommand)e.OldValue, (ICommand)e.NewValue);
        }
예제 #14
0
        private static object CoerceHasSubItems(DependencyObject d, object value)
        {
            NavigationPaneItem item = d as NavigationPaneItem;

            return(item.SubItems.Count > 0);
        }