Exemplo n.º 1
0
 public static CollectionWrapper GetCollectionWrapperInstance(IEnumerable collection, bool shareCollectionPerThread)
 {
     if (shareCollectionPerThread)
     {
         lock (CollectionWrapper.collectionWrappers)
         {
             Dispatcher CurrentDispatcher = Dispatcher.CurrentDispatcher;
             if (CollectionWrapper.collectionWrappers.ContainsKey(CurrentDispatcher))
             {
                 return(CollectionWrapper.GetCollectionWrapperInstance(CollectionWrapper.collectionWrappers[CurrentDispatcher], collection,
                                                                       CurrentDispatcher));
             }
             else
             {
                 Dictionary <IEnumerable, CollectionWrapper> CollectionWrappers =
                     new Dictionary <IEnumerable, CollectionWrapper>();
                 CollectionWrapper.collectionWrappers.Add(CurrentDispatcher, CollectionWrappers);
                 return(CollectionWrapper.GetCollectionWrapperInstance(CollectionWrappers, collection, CurrentDispatcher));
             }
         }
     }
     else
     {
         return(new CollectionWrapper(collection, Dispatcher.CurrentDispatcher));
     }
 }
Exemplo n.º 2
0
 private static CollectionWrapper GetCollectionWrapperInstance(IDictionary <IEnumerable, CollectionWrapper> collectionWrappers, IEnumerable collection, Dispatcher dispatcher)
 {
     lock (collectionWrappers)
     {
         if (collectionWrappers.ContainsKey(collection))
         {
             return(collectionWrappers[collection]);
         }
         else
         {
             CollectionWrapper Wrapper = new CollectionWrapper(collection, dispatcher);
             collectionWrappers.Add(collection, Wrapper);
             return(Wrapper);
         }
     }
 }
        /// <summary>
        /// Converts a value.
        /// </summary>
        /// <returns>
        /// A converted value. If the method returns null, the valid null value is used.
        /// </returns>
        /// <param name="value">The value produced by the binding source.</param><param name="targetType">The type of the binding target property.</param><param name="parameter">The converter parameter to use.</param><param name="culture">The culture to use in the converter.</param>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            object Collection = value;

            if (Collection == null)
            {
                return(null);
            }
            else if (Collection is IEnumerable && Collection is INotifyCollectionChanged)
            {
                return(CollectionWrapper.GetCollectionWrapperInstance((IEnumerable)Collection, this.ShareCollectionPerThread));
            }
            else
            {
                throw new InvalidOperationException("Collection to wrap is either not enumerable or does not support INotifyCollectionChanged");
            }
        }