/// <summary>
        /// Convert forward function.
        /// </summary>
        /// <param name="value">The source value.</param>
        /// <param name="targetType">The target type.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="culture">The culture info.</param>
        /// <returns>The converted value.</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool negated = false;

            if (parameter != null)
            {
                if (!bool.TryParse(parameter.ToString(), out negated))
                {
                    negated = false;
                }
            }

            if (value == null)
            {
                return(negated ? Visibility.Visible : Visibility.Collapsed);
            }

            IEnumerable list = value as IEnumerable;

            if (!(list is string) && list != null && IEnumerableHelper.GetItemCount(list) > 0)
            {
                return(negated ? Visibility.Collapsed : Visibility.Visible);
            }

            if (value != null && !string.IsNullOrEmpty(value.ToString()))
            {
                return(negated ? Visibility.Collapsed : Visibility.Visible);
            }

            return(negated ? Visibility.Visible : Visibility.Collapsed);
        }
Esempio 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
        }