Beispiel #1
0
 public static CollectionWrapper GetCollectionWrapperInstance(IEnumerable collection /*, bool shareCollectionPerThread*/)
 {
     //if (shareCollectionPerThread)
     //{
     lock (CollectionWrapper.collectionWrappers)
     {
         return(CollectionWrapper.GetCollectionWrapperInstance(CollectionWrapper.collectionWrappers, collection));
     }
     //}
     //else
     //{
     //    return new CollectionWrapper(collection, Dispatcher.CurrentDispatcher);
     //}
 }
Beispiel #2
0
 private static CollectionWrapper GetCollectionWrapperInstance(IDictionary <IEnumerable, CollectionWrapper> collectionWrappers, IEnumerable collection)
 {
     lock (collectionWrappers)
     {
         if (collectionWrappers.ContainsKey(collection))
         {
             return(collectionWrappers[collection]);
         }
         else
         {
             CollectionWrapper Wrapper = new CollectionWrapper(collection);
             collectionWrappers.Add(collection, Wrapper);
             return(Wrapper);
         }
     }
 }
        ///// <summary>
        ///// specifies wether fade in/out animations for items are enabled for the items control
        ///// </summary>
        //public static readonly BindableProperty EnableItemFadeAnimationsProperty = BindableProperty.CreateAttached("EnableItemFadeAnimations", typeof(bool), typeof(CrossThreadCollectionWrapper), false,propertyChanged: CrossThreadCollectionWrapper.EnableItemFadeAnimationsChanged));
        ///// <summary>
        ///// specifies the storyboard for the fade in animation
        ///// </summary>
        //public static readonly BindableProperty FadeInAnimationProperty = BindableProperty.CreateAttached("FadeInAnimation", typeof(Storyboard), typeof(CrossThreadCollectionWrapper));
        ///// <summary>
        ///// specifies the storyboard for the fade out animation
        ///// </summary>
        //public static readonly BindableProperty FadeOutAnimationProperty = BindableProperty.CreateAttached("FadeOutAnimation", typeof(Storyboard), typeof(CrossThreadCollectionWrapper));

        //private static void EnableItemFadeAnimationsChanged(BindableObject bindable, object oldValue, object newValue)
        //{
        //    ItemsControl ItemsControl = (ItemsControl) d;
        //    CollectionWrapper.RegisteredControls.Add(ItemsControl);
        //}

        ///// <summary/>
        //public CrossThreadCollectionWrapper()
        //{
        //    this.ShareCollectionPerControl = true;
        //}

        #region IValueConverter Members

        /// <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.ShareCollectionPerControl*/));
            }
            else
            {
                throw new InvalidOperationException("Collection to wrap is either not enumerable or does not support INotifyCollectionChanged");
            }
        }