//------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        /// <summary>
        /// Return the group name(s) for the given item
        /// </summary>
        public override object GroupNameFromItem(object item, int level, CultureInfo culture)
        {
            object value;
            object xmlValue;

            // get the property value
            if (String.IsNullOrEmpty(PropertyName))
            {
                value = item;
            }
            else if (SystemXmlHelper.TryGetValueFromXmlNode(item, PropertyName, out xmlValue))
            {
                value = xmlValue;
            }
            else if (item != null)
            {
                using (_propertyPath.SetContext(item))
                {
                    value = _propertyPath.GetValue();
                }
            }
            else
            {
                value = null;
            }

            // apply the converter to the value
            if (Converter != null)
            {
                value = Converter.Convert(value, typeof(object), level, culture);
            }

            return(value);
        }
 /// <summary>
 /// Override this method to return an app specific <seealso cref="DataTemplate"/>.
 /// </summary>
 /// <param name="item">The data content</param>
 /// <param name="container">The container in which the content is to be displayed</param>
 /// <returns>a app specific template to apply.</returns>
 public override DataTemplate SelectTemplate(object item, DependencyObject container)
 {
     if (SystemXmlHelper.IsXmlNode(item))
     {
         if (_xmlNodeContentTemplate == null)
         {
             _xmlNodeContentTemplate = new DataTemplate();
             FrameworkElementFactory text = ContentPresenter.CreateTextBlockFactory();
             Binding binding = new Binding();
             binding.XPath        = _displayMemberPath;
             binding.StringFormat = _stringFormat;
             text.SetBinding(TextBlock.TextProperty, binding);
             _xmlNodeContentTemplate.VisualTree = text;
             _xmlNodeContentTemplate.Seal();
         }
         return(_xmlNodeContentTemplate);
     }
     else
     {
         if (_clrNodeContentTemplate == null)
         {
             _clrNodeContentTemplate = new DataTemplate();
             FrameworkElementFactory text = ContentPresenter.CreateTextBlockFactory();
             Binding binding = new Binding();
             binding.Path         = new PropertyPath(_displayMemberPath);
             binding.StringFormat = _stringFormat;
             text.SetBinding(TextBlock.TextProperty, binding);
             _clrNodeContentTemplate.VisualTree = text;
             _clrNodeContentTemplate.Seal();
         }
         return(_clrNodeContentTemplate);
     }
 }
        // Token: 0x06004412 RID: 17426 RVA: 0x00136610 File Offset: 0x00134810
        internal static object DataTypeForItem(object item, DependencyObject target, out Type type)
        {
            if (item == null)
            {
                type = null;
                return(null);
            }
            type = ReflectionHelper.GetReflectionType(item);
            object result;

            if (SystemXmlLinqHelper.IsXElement(item))
            {
                result = SystemXmlLinqHelper.GetXElementTagName(item);
                type   = null;
            }
            else if (SystemXmlHelper.IsXmlNode(item))
            {
                result = SystemXmlHelper.GetXmlTagName(item, target);
                type   = null;
            }
            else if (type == typeof(object))
            {
                result = null;
            }
            else
            {
                result = type;
            }
            return(result);
        }
Пример #4
0
        internal static object DataTypeForItem(object item, DependencyObject target, out Type type)
        {
            if (item == null)
            {
                type = null;
                return(null);
            }

            object dataType;

            type = ReflectionHelper.GetReflectionType(item);

            if (SystemXmlLinqHelper.IsXElement(item))
            {
                dataType = SystemXmlLinqHelper.GetXElementTagName(item);
                type     = null;
            }
            else if (SystemXmlHelper.IsXmlNode(item))
            {
                dataType = SystemXmlHelper.GetXmlTagName(item, target);
                type     = null;
            }
            else if (type == typeof(Object))
            {
                dataType = null;     // don't search for Object - perf
            }
            else
            {
                dataType = type;
            }

            return(dataType);
        }
 // Token: 0x06007505 RID: 29957 RVA: 0x002177D4 File Offset: 0x002159D4
 public override DataTemplate SelectTemplate(object item, DependencyObject container)
 {
     if (SystemXmlHelper.IsXmlNode(item))
     {
         if (this._xmlNodeContentTemplate == null)
         {
             this._xmlNodeContentTemplate = new DataTemplate();
             FrameworkElementFactory frameworkElementFactory = ContentPresenter.CreateTextBlockFactory();
             Binding binding = new Binding();
             binding.XPath        = this._displayMemberPath;
             binding.StringFormat = this._stringFormat;
             frameworkElementFactory.SetBinding(TextBlock.TextProperty, binding);
             this._xmlNodeContentTemplate.VisualTree = frameworkElementFactory;
             this._xmlNodeContentTemplate.Seal();
         }
         return(this._xmlNodeContentTemplate);
     }
     if (this._clrNodeContentTemplate == null)
     {
         this._clrNodeContentTemplate = new DataTemplate();
         FrameworkElementFactory frameworkElementFactory2 = ContentPresenter.CreateTextBlockFactory();
         Binding binding2 = new Binding();
         binding2.Path         = new PropertyPath(this._displayMemberPath, new object[0]);
         binding2.StringFormat = this._stringFormat;
         frameworkElementFactory2.SetBinding(TextBlock.TextProperty, binding2);
         this._clrNodeContentTemplate.VisualTree = frameworkElementFactory2;
         this._clrNodeContentTemplate.Seal();
     }
     return(this._clrNodeContentTemplate);
 }
Пример #6
0
        /// <summary>Returns the group name(s) for the given item. </summary>
        /// <param name="item">The item to return group names for.</param>
        /// <param name="level">The level of grouping.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to supply to the converter.</param>
        /// <returns>The group name(s) for the given item.</returns>
        // Token: 0x06001C95 RID: 7317 RVA: 0x0008632C File Offset: 0x0008452C
        public override object GroupNameFromItem(object item, int level, CultureInfo culture)
        {
            object obj;
            object obj2;

            if (string.IsNullOrEmpty(this.PropertyName))
            {
                obj = item;
            }
            else if (SystemXmlHelper.TryGetValueFromXmlNode(item, this.PropertyName, out obj2))
            {
                obj = obj2;
            }
            else
            {
                if (item != null)
                {
                    using (this._propertyPath.SetContext(item))
                    {
                        obj = this._propertyPath.GetValue();
                        goto IL_4F;
                    }
                }
                obj = null;
            }
IL_4F:
            if (this.Converter != null)
            {
                obj = this.Converter.Convert(obj, typeof(object), level, culture);
            }
            return(obj);
        }
Пример #7
0
        internal void SetBinding(string path, DependencyProperty dp, bool oneTime = false, bool enableXT = false)
        {
            if (enableXT && oneTime)
            {
                enableXT = false;
            }

            if (!LookupEntry(dp.GlobalIndex).Found)
            {
                if (!String.IsNullOrEmpty(path))
                {
                    Binding binding;
                    if (SystemXmlHelper.IsXmlNode(_item))
                    {
                        binding       = new Binding();
                        binding.XPath = path;
                    }
                    else
                    {
                        binding = new Binding(path);
                    }

                    binding.Source = _item;
                    if (oneTime)
                    {
                        binding.Mode = BindingMode.OneTime;
                    }

                    //BindingExpressionBase beb = BindingOperations.SetBinding(this, dp, binding);
                    // we need to set the cross-thread flag before the binding is
                    // attached, in case the source raises PropertyChanged events
                    // right away.  So don't call BO.SetBinding, but imitate its effect
                    BindingExpressionBase beb = binding.CreateBindingExpression(this, dp);
                    if (enableXT)
                    {
                        beb.TargetWantsCrossThreadNotifications = true;
                    }
                    this.SetValue(dp, beb);
                }
                else if (!oneTime)
                {
                    // when the path is empty, react to any property change
                    INotifyPropertyChanged inpc = Item as INotifyPropertyChanged;
                    if (inpc != null)
                    {
                        PropertyChangedEventManager.AddHandler(inpc, OnPropertyChanged, String.Empty);
                    }
                }
            }
        }
        // Token: 0x060057FE RID: 22526 RVA: 0x00186080 File Offset: 0x00184280
        private static BindingExpression CreateBindingExpression(ItemsControl itemsControl, object item, string primaryTextPath)
        {
            Binding binding = new Binding();

            if (SystemXmlHelper.IsXmlNode(item))
            {
                binding.XPath = primaryTextPath;
                binding.Path  = new PropertyPath("/InnerText", new object[0]);
            }
            else
            {
                binding.Path = new PropertyPath(primaryTextPath, new object[0]);
            }
            binding.Mode   = BindingMode.OneWay;
            binding.Source = null;
            return((BindingExpression)BindingExpressionBase.CreateUntargetedBindingExpression(itemsControl, binding));
        }
Пример #9
0
            /// <summary>
            /// Override this method to return an app specific <seealso cref="Template"/>.
            /// </summary>
            /// <param name="item">The data content</param>
            /// <param name="container">The container in which the content is to be displayed</param>
            /// <returns>a app specific template to apply.</returns>
            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                DataTemplate template = null;

                // Lookup template for typeof(Content) in resource dictionaries.
                if (item != null)
                {
                    template = (DataTemplate)FrameworkElement.FindTemplateResourceInternal(container, item, typeof(DataTemplate));
                }

                // default templates for well known types:
                if (template == null)
                {
                    TypeConverter tc = null;
                    string        s;

                    if ((s = item as string) != null)
                    {
                        template = ((ContentPresenter)container).SelectTemplateForString(s);
                    }
                    else if (item is UIElement)
                    {
                        template = UIElementContentTemplate;
                    }
                    else if (SystemXmlHelper.IsXmlNode(item))
                    {
                        template = ((ContentPresenter)container).SelectTemplateForXML();
                    }
                    else if (item is Inline)
                    {
                        template = DefaultContentTemplate;
                    }
                    else if (item != null &&
                             (tc = TypeDescriptor.GetConverter(ReflectionHelper.GetReflectionType(item))) != null &&
                             tc.CanConvertTo(typeof(UIElement)))
                    {
                        template = UIElementContentTemplate;
                    }
                    else
                    {
                        template = DefaultContentTemplate;
                    }
                }

                return(template);
            }
Пример #10
0
        private BindingExpression PrepareSelectedValuePathBindingExpression(object item)
        {
            if (item == null)
            {
                return(null);
            }

            Binding binding;
            bool    useXml = SystemXmlHelper.IsXmlNode(item);

            BindingExpression bindingExpr = SelectedValuePathBindingExpression.GetValue(this);

            // replace existing binding if it's the wrong kind
            if (bindingExpr != null)
            {
                binding = bindingExpr.ParentBinding;
                bool usesXml = (binding.XPath != null);
                if (usesXml != useXml)
                {
                    bindingExpr = null;
                }
            }

            if (bindingExpr == null)
            {
                // create the binding
                binding        = new Binding();
                binding.Source = item;

                if (useXml)
                {
                    binding.XPath = SelectedValuePath;
                    binding.Path  = new PropertyPath("/InnerText");
                }
                else
                {
                    binding.Path = new PropertyPath(SelectedValuePath);
                }

                bindingExpr = (BindingExpression)BindingExpression.CreateUntargetedBindingExpression(this, binding);
                SelectedValuePathBindingExpression.SetValue(this, bindingExpr);
            }

            return(bindingExpr);
        }
        internal void SetBinding(string path, DependencyProperty dp, bool oneTime = false, bool enableXT = false)
        {
            if (enableXT && oneTime)
            {
                enableXT = false;
            }

            if (!LookupEntry(dp.GlobalIndex).Found)
            {
                if (!String.IsNullOrEmpty(path))
                {
                    Binding binding;
                    if (SystemXmlHelper.IsXmlNode(_item))
                    {
                        binding       = new Binding();
                        binding.XPath = path;
                    }
                    else
                    {
                        binding = new Binding(path);
                    }

                    binding.Source = _item;
                    if (oneTime)
                    {
                        binding.Mode = BindingMode.OneTime;
                    }
                    BindingExpressionBase beb = BindingOperations.SetBinding(this, dp, binding);
                    if (enableXT)
                    {
                        beb.TargetWantsCrossThreadNotifications = true;
                    }
                }
                else if (!oneTime)
                {
                    // when the path is empty, react to any property change
                    INotifyPropertyChanged inpc = Item as INotifyPropertyChanged;
                    if (inpc != null)
                    {
                        PropertyChangedEventManager.AddHandler(inpc, OnPropertyChanged, String.Empty);
                    }
                }
            }
        }
Пример #12
0
        private static BindingExpression CreateBindingExpression(ItemsControl itemsControl, object item, string primaryTextPath)
        {
            Binding binding = new Binding();

            // Use xpath for xmlnodes (See Selector.PrepareItemValueBinding)
            if (SystemXmlHelper.IsXmlNode(item))
            {
                binding.XPath = primaryTextPath;
                binding.Path  = new PropertyPath("/InnerText");
            }
            else
            {
                binding.Path = new PropertyPath(primaryTextPath);
            }

            binding.Mode   = BindingMode.OneWay;
            binding.Source = null;
            return((BindingExpression)BindingExpression.CreateUntargetedBindingExpression(itemsControl, binding));
        }
Пример #13
0
 // Token: 0x0600759C RID: 30108 RVA: 0x00219438 File Offset: 0x00217638
 internal void SetBinding(string path, DependencyProperty dp, bool oneTime = false, bool enableXT = false)
 {
     if (enableXT && oneTime)
     {
         enableXT = false;
     }
     if (!base.LookupEntry(dp.GlobalIndex).Found)
     {
         if (!string.IsNullOrEmpty(path))
         {
             Binding binding;
             if (SystemXmlHelper.IsXmlNode(this._item))
             {
                 binding       = new Binding();
                 binding.XPath = path;
             }
             else
             {
                 binding = new Binding(path);
             }
             binding.Source = this._item;
             if (oneTime)
             {
                 binding.Mode = BindingMode.OneTime;
             }
             BindingExpressionBase bindingExpressionBase = binding.CreateBindingExpression(this, dp);
             if (enableXT)
             {
                 bindingExpressionBase.TargetWantsCrossThreadNotifications = true;
             }
             base.SetValue(dp, bindingExpressionBase);
             return;
         }
         if (!oneTime)
         {
             INotifyPropertyChanged notifyPropertyChanged = this.Item as INotifyPropertyChanged;
             if (notifyPropertyChanged != null)
             {
                 PropertyChangedEventManager.AddHandler(notifyPropertyChanged, new EventHandler <PropertyChangedEventArgs>(this.OnPropertyChanged), string.Empty);
             }
         }
     }
 }
            // Token: 0x06008730 RID: 34608 RVA: 0x0024F2AC File Offset: 0x0024D4AC
            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                DataTemplate dataTemplate = null;

                if (item != null)
                {
                    dataTemplate = (DataTemplate)FrameworkElement.FindTemplateResourceInternal(container, item, typeof(DataTemplate));
                }
                if (dataTemplate == null)
                {
                    string        s;
                    TypeConverter converter;
                    if ((s = (item as string)) != null)
                    {
                        dataTemplate = ((ContentPresenter)container).SelectTemplateForString(s);
                    }
                    else if (item is UIElement)
                    {
                        dataTemplate = ContentPresenter.UIElementContentTemplate;
                    }
                    else if (SystemXmlHelper.IsXmlNode(item))
                    {
                        dataTemplate = ((ContentPresenter)container).SelectTemplateForXML();
                    }
                    else if (item is Inline)
                    {
                        dataTemplate = ContentPresenter.DefaultContentTemplate;
                    }
                    else if (item != null && (converter = TypeDescriptor.GetConverter(ReflectionHelper.GetReflectionType(item))) != null && converter.CanConvertTo(typeof(UIElement)))
                    {
                        dataTemplate = ContentPresenter.UIElementContentTemplate;
                    }
                    else
                    {
                        dataTemplate = ContentPresenter.DefaultContentTemplate;
                    }
                }
                return(dataTemplate);
            }
Пример #15
0
        // Token: 0x060058D9 RID: 22745 RVA: 0x0018931C File Offset: 0x0018751C
        private BindingExpression PrepareSelectedValuePathBindingExpression(object item)
        {
            if (item == null)
            {
                return(null);
            }
            bool flag = SystemXmlHelper.IsXmlNode(item);
            BindingExpression bindingExpression = TreeView.SelectedValuePathBindingExpression.GetValue(this);

            if (bindingExpression != null)
            {
                Binding binding = bindingExpression.ParentBinding;
                bool    flag2   = binding.XPath != null;
                if (flag2 != flag)
                {
                    bindingExpression = null;
                }
            }
            if (bindingExpression == null)
            {
                Binding binding = new Binding();
                binding.Source = null;
                if (flag)
                {
                    binding.XPath = this.SelectedValuePath;
                    binding.Path  = new PropertyPath("/InnerText", new object[0]);
                }
                else
                {
                    binding.Path = new PropertyPath(this.SelectedValuePath, new object[0]);
                }
                bindingExpression = (BindingExpression)BindingExpressionBase.CreateUntargetedBindingExpression(this, binding);
                TreeView.SelectedValuePathBindingExpression.SetValue(this, bindingExpression);
            }
            return(bindingExpression);
        }
Пример #16
0
        /// <summary>
        ///     Searches through the given itemCollection for the first item matching the given prefix.
        /// </summary>
        /// <remarks>
        ///     --------------------------------------------------------------------------
        ///     Incremental Type Search algorithm
        ///     --------------------------------------------------------------------------
        ///
        ///     Given a prefix and new character, we loop through all items in the collection
        ///     and look for an item that starts with the new prefix.  If we find such an item,
        ///     select it.  If the new character is repeated, we look for the next item after
        ///     the current one that begins with the old prefix**.  We can optimize by
        ///     performing both of these searches in parallel.
        ///
        ///     **NOTE: Win32 will only do this if the old prefix is of length 1 - in other
        ///             words, first-character-only matching.  The algorithm described here
        ///             is an extension of ITS as implemented in Win32.  This variant was
        ///             described to me by JeffBog as what was done in AFC - but I have yet
        ///             to find a listbox which behaves this way.
        ///
        ///     --------------------------------------------------------------------------
        /// </remarks>
        /// <returns>Item that matches the given prefix</returns>
        private static int FindMatchingPrefix(ItemsControl itemsControl, string primaryTextPath, string prefix,
                                              string newChar, int startItemIndex, bool lookForFallbackMatchToo, ref bool wasNewCharUsed)
        {
            ItemCollection itemCollection = itemsControl.Items;

            // Using indices b/c this is a better way to uniquely
            // identify an element in the collection.
            int matchedItemIndex   = -1;
            int fallbackMatchIndex = -1;

            int count = itemCollection.Count;

            // Return immediately with no match if there were no items in the view.
            if (count == 0)
            {
                return(-1);
            }

            string newPrefix = prefix + newChar;

            // With an empty prefix, we'd match anything
            if (String.IsNullOrEmpty(newPrefix))
            {
                return(-1);
            }

            // Hook up the binding we will apply to each object.  Get the
            // PrimaryTextPath off of the attached instance and then make
            // a binding with that path.

            BindingExpression primaryTextBinding = null;

            object item0  = itemsControl.Items[0];
            bool   useXml = SystemXmlHelper.IsXmlNode(item0);

            if (useXml || !String.IsNullOrEmpty(primaryTextPath))
            {
                primaryTextBinding = CreateBindingExpression(itemsControl, item0, primaryTextPath);
                TextValueBindingExpression.SetValue(itemsControl, primaryTextBinding);
            }
            bool firstItem = true;

            wasNewCharUsed = false;

            CultureInfo cultureInfo = GetCulture(itemsControl);

            // ISSUE: what about changing the collection while this is running?
            for (int currentIndex = startItemIndex; currentIndex < count;)
            {
                object item = itemCollection[currentIndex];

                if (item != null)
                {
                    string itemString = GetPrimaryText(item, primaryTextBinding, itemsControl);
                    bool   isTextSearchCaseSensitive = itemsControl.IsTextSearchCaseSensitive;

                    // See if the current item matches the newPrefix, if so we can
                    // stop searching and accept this item as the match.
                    if (itemString != null && itemString.StartsWith(newPrefix, !isTextSearchCaseSensitive, cultureInfo))
                    {
                        // Accept the new prefix as the current prefix.
                        wasNewCharUsed   = true;
                        matchedItemIndex = currentIndex;
                        break;
                    }

                    // Find the next string that matches the last prefix.  This
                    // string will be used in the case that the new prefix isn't
                    // matched. This enables pressing the last character multiple
                    // times and cylcing through the set of items that match that
                    // prefix.
                    //
                    // Unlike the above search, this search must start *after*
                    // the currently selected item.  This search also shouldn't
                    // happen if there was no previous prefix to match against
                    if (lookForFallbackMatchToo)
                    {
                        if (!firstItem && prefix != String.Empty)
                        {
                            if (itemString != null)
                            {
                                if (fallbackMatchIndex == -1 && itemString.StartsWith(prefix, !isTextSearchCaseSensitive, cultureInfo))
                                {
                                    fallbackMatchIndex = currentIndex;
                                }
                            }
                        }
                        else
                        {
                            firstItem = false;
                        }
                    }
                }

                // Move next and wrap-around if we pass the end of the container.
                currentIndex++;
                if (currentIndex >= count)
                {
                    currentIndex = 0;
                }

                // Stop where we started but only after the first pass
                // through the loop -- we should process the startItem.
                if (currentIndex == startItemIndex)
                {
                    break;
                }
            }

            if (primaryTextBinding != null)
            {
                // Clean up the binding for the primary text path.
                TextValueBindingExpression.ClearValue(itemsControl);
            }

            // In the case that the new prefix didn't match anything and
            // there was a fallback match that matched the old prefix, move
            // to that one.
            if (matchedItemIndex == -1 && fallbackMatchIndex != -1)
            {
                matchedItemIndex = fallbackMatchIndex;
            }

            return(matchedItemIndex);
        }
Пример #17
0
 private static bool IsValidXmlNamespaceManager(object value)
 {
     return((value == null) || SystemXmlHelper.IsXmlNamespaceManager(value));
 }
        // Token: 0x060057F6 RID: 22518 RVA: 0x00185D48 File Offset: 0x00183F48
        private static int FindMatchingPrefix(ItemsControl itemsControl, string primaryTextPath, string prefix, string newChar, int startItemIndex, bool lookForFallbackMatchToo, ref bool wasNewCharUsed)
        {
            ItemCollection items = itemsControl.Items;
            int            num   = -1;
            int            num2  = -1;
            int            count = items.Count;

            if (count == 0)
            {
                return(-1);
            }
            string value = prefix + newChar;

            if (string.IsNullOrEmpty(value))
            {
                return(-1);
            }
            BindingExpression bindingExpression = null;
            object            item = itemsControl.Items[0];

            if (SystemXmlHelper.IsXmlNode(item) || !string.IsNullOrEmpty(primaryTextPath))
            {
                bindingExpression = TextSearch.CreateBindingExpression(itemsControl, item, primaryTextPath);
                TextSearch.TextValueBindingExpression.SetValue(itemsControl, bindingExpression);
            }
            bool flag = true;

            wasNewCharUsed = false;
            CultureInfo culture = TextSearch.GetCulture(itemsControl);
            int         i       = startItemIndex;

            while (i < count)
            {
                object obj = items[i];
                if (obj != null)
                {
                    string primaryText = TextSearch.GetPrimaryText(obj, bindingExpression, itemsControl);
                    bool   isTextSearchCaseSensitive = itemsControl.IsTextSearchCaseSensitive;
                    if (primaryText != null && primaryText.StartsWith(value, !isTextSearchCaseSensitive, culture))
                    {
                        wasNewCharUsed = true;
                        num            = i;
                        break;
                    }
                    if (lookForFallbackMatchToo)
                    {
                        if (!flag && prefix != string.Empty)
                        {
                            if (primaryText != null && num2 == -1 && primaryText.StartsWith(prefix, !isTextSearchCaseSensitive, culture))
                            {
                                num2 = i;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                }
                i++;
                if (i >= count)
                {
                    i = 0;
                }
                if (i == startItemIndex)
                {
                    break;
                }
            }
            if (bindingExpression != null)
            {
                TextSearch.TextValueBindingExpression.ClearValue(itemsControl);
            }
            if (num == -1 && num2 != -1)
            {
                num = num2;
            }
            return(num);
        }