Exemplo n.º 1
0
        /// <summary>
        /// Prepares the split list box item.
        /// </summary>
        /// <param name="element">The split list box item.</param>
        /// <param name="item">The item object.</param>
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            if (this.verticalScrollBar == null)
            {
                this.verticalScrollBar = this.GetVerticalScrollBar(element) as ScrollBar;
                if (this.verticalScrollBar != null)
                {
                    this.verticalScrollBar.Scroll       += new ScrollEventHandler(this.VerticalScrollBar_Scroll);
                    this.verticalScrollBar.ValueChanged += new RoutedPropertyChangedEventHandler <double>(this.VerticalScrollBar_ValueChanged);
                }
            }

            SplitListBoxItem splitListBoxItem = element as SplitListBoxItem;

            if (splitListBoxItem != null)
            {
                splitListBoxItem.ParentSplitListBox = this;
                splitListBoxItem.ItemSelected      += new EventHandler <SelectedEventArgs>(this.SplitListBoxItem_Selected);

                if (!this.containersByItem.ContainsKey(item))
                {
                    this.containersByItem.Add(item, splitListBoxItem);
                }
                else
                {
                    this.containersByItem[item] = splitListBoxItem;
                }

                if (this.ItemHeaderTemplate != null)
                {
                    splitListBoxItem.HeaderTemplate = this.ItemHeaderTemplate;
                }

                if (this.itemHeadersByItem.ContainsKey(item))
                {
                    splitListBoxItem.Header = this.itemHeadersByItem[item];
                    this.itemHeadersByItem.Remove(item);
                }

                if (this.shortcutKeysByItem.ContainsKey(item))
                {
                    splitListBoxItem.ShortcutKeyText        = ShortcutKeyHelper.ShortcutKeyPrefix + ShortcutKeyHelper.GetKeyAsString(this.shortcutKeysByItem[item]);
                    splitListBoxItem.ShortcutKeyTextOpacity = this.showingShortcutKeys ? 1.0 : 0.0;
                }

                if (this.splitItems.Contains(item))
                {
                    splitListBoxItem.SplitBorderThickness = this.SplitBorderThickness;
                    splitListBoxItem.SplitBorderBrush     = this.SplitBorderBrush;
                }

                if (item == this.OtherItem && this.OtherItemTemplate != null)
                {
                    splitListBoxItem.ContentTemplate = this.OtherItemTemplate;
                }
                else if (item == this.CustomValueItem && this.CustomValueItemTemplate != null)
                {
                    splitListBoxItem.ContentTemplate = this.CustomValueItemTemplate;
                }

                this.UpdateItemBackgrounds();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the items source of a split items control.
        /// </summary>
        /// <param name="splitItemsControl">The split items control.</param>
        public static void UpdateItemsSource(ISplitItemsControl splitItemsControl)
        {
#if !SILVERLIGHT
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(splitItemsControl as DependencyObject))
            {
                return;
            }
#endif

            List <object> items = new List <object>();
            if (splitItemsControl.PrimaryItemsSource != null)
            {
                items.AddRange(IEnumerableHelper.GetItems(splitItemsControl.PrimaryItemsSource));
                if (items.Count > 0)
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (splitItemsControl.PrimaryItemsSourceHeader != null)
                        {
                            splitItemsControl.AddItemHeader(items[i], null);
                        }

                        if (splitItemsControl.AddShortcutKeysToPrimaryItems && i <= 10)
                        {
                            splitItemsControl.AddItemShortcutKey(items[i], ShortcutKeyHelper.GetKeyFromIndex(i));
                        }
                        else
                        {
                            splitItemsControl.RemoveItemShortcutKey(items[i], ShortcutKeyHelper.GetKeyFromIndex(i));
                        }

                        splitItemsControl.RemoveItemSplit(items[i]);
                    }

                    splitItemsControl.AddItemHeader(items[0], splitItemsControl.PrimaryItemsSourceHeader);
                }
            }

            if (splitItemsControl.SecondaryItemsSource != null)
            {
                if (items.Count > 0)
                {
                    splitItemsControl.AddItemSplit(items[items.Count - 1]);
                }

                int itemCount = items.Count;
                items.AddRange(IEnumerableHelper.GetItems(splitItemsControl.SecondaryItemsSource));

                if (splitItemsControl.SecondaryItemsSourceHeader != null && items.Count > itemCount)
                {
                    for (int i = itemCount; i < items.Count; i++)
                    {
                        splitItemsControl.AddItemHeader(items[i], null);
                        splitItemsControl.RemoveItemSplit(items[i]);
                    }

                    splitItemsControl.AddItemHeader(items[itemCount], splitItemsControl.SecondaryItemsSourceHeader);
                }
            }

            if (splitItemsControl.ShowCustomValueOption && splitItemsControl.CustomValueItem != null)
            {
                if (items.Count > 0)
                {
                    splitItemsControl.AddItemSplit(items[items.Count - 1]);
                }

                items.Add(splitItemsControl.CustomValueItem);
            }

            if (splitItemsControl.OtherItemsSource != null && splitItemsControl.ShowOtherItems)
            {
                if (items.Count > 0)
                {
                    splitItemsControl.AddItemSplit(items[items.Count - 1]);
                }

                int itemCount = items.Count;
                items.AddRange(IEnumerableHelper.GetItems(splitItemsControl.OtherItemsSource));
                if (splitItemsControl.OtherItemsSourceHeader != null && items.Count > itemCount)
                {
                    for (int i = itemCount; i < items.Count; i++)
                    {
                        splitItemsControl.AddItemHeader(items[i], null);
                        splitItemsControl.RemoveItemSplit(items[i]);
                    }

                    splitItemsControl.AddItemHeader(items[itemCount], splitItemsControl.OtherItemsSourceHeader);
                }
            }
            else if (splitItemsControl.ShowOtherOption)
            {
                if (items.Count > 0)
                {
                    splitItemsControl.AddItemSplit(items[items.Count - 1]);
                }

                items.Add(splitItemsControl.OtherItem);
            }

            splitItemsControl.ItemsSource = items;

#if !SILVERLIGHT
            if (splitItemsControl is SplitComboBox)
            {
                object selectedItem = null;
                foreach (object item in items)
                {
                    SplitComboBoxItem splitComboBoxItem = item as SplitComboBoxItem;
                    if (splitComboBoxItem != null && splitComboBoxItem.IsSelected)
                    {
                        selectedItem = item;
                        break;
                    }
                }

                if (selectedItem != null)
                {
                    splitItemsControl.SelectedItem = selectedItem;
                }
            }
#endif
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a shortcut key to an item.
        /// </summary>
        /// <param name="item">The item to add the key too.</param>
        /// <param name="key">The short cut key.</param>
        public void AddItemShortcutKey(object item, Key?key)
        {
            if (key.HasValue && item != null)
            {
                if (this.itemsByShortcutKey.ContainsKey(key.Value))
                {
                    this.itemsByShortcutKey[key.Value] = item;
                }
                else
                {
                    this.itemsByShortcutKey.Add(key.Value, item);
                }

                if (this.shortcutKeysByItem.ContainsKey(item))
                {
                    this.shortcutKeysByItem[item] = key.Value;
                }
                else
                {
                    this.shortcutKeysByItem.Add(item, key.Value);
                }

                if (this.containersByItem.ContainsKey(item))
                {
                    this.containersByItem[item].ShortcutKeyText        = ShortcutKeyHelper.ShortcutKeyPrefix + ShortcutKeyHelper.GetKeyAsString(key.Value);
                    this.containersByItem[item].ShortcutKeyTextOpacity = this.showingShortcutKeys ? 1.0 : 0.0;
                }
            }
        }