Exemplo n.º 1
0
        public void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
        {
            ListViewItemGenerator icg = (ListViewItemGenerator)source;

            _itemTemplate       = copyManager.GetCopy(icg._itemTemplate);
            _itemContainerStyle = copyManager.GetCopy(icg._itemContainerStyle);
            _parent             = copyManager.GetCopy(icg._parent);
            if (icg._items == null)
            {
                _items = null;
            }
            else
            {
                _items = new List <object>(icg._items.Count);
                foreach (object item in icg._items)
                {
                    _items.Add(copyManager.GetCopy(item));
                }
            }
            _populatedStartIndex = icg._populatedStartIndex;
            _populatedEndIndex   = icg._populatedEndIndex;
            if (icg._materializedItems == null)
            {
                _materializedItems = null;
            }
            else
            {
                _materializedItems = new List <FrameworkElement>(icg._materializedItems.Count);
                foreach (FrameworkElement item in icg._materializedItems)
                {
                    _materializedItems.Add(copyManager.GetCopy(item));
                }
            }
        }
Exemplo n.º 2
0
        public void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
        {
            ListViewItemGenerator icg = (ListViewItemGenerator)source;

            _itemTemplate       = copyManager.GetCopy(icg._itemTemplate);
            _itemContainerStyle = copyManager.GetCopy(icg._itemContainerStyle);

            _groupingValueProvider     = icg._groupingValueProvider;
            _groupPropertyBinding      = copyManager.GetCopy(icg._groupPropertyBinding);
            _groupHeaderTemplate       = copyManager.GetCopy(icg._groupHeaderTemplate);
            _groupHeaderContainerStyle = copyManager.GetCopy(icg._groupHeaderContainerStyle);

            _parent = copyManager.GetCopy(icg._parent);
            if (icg._items == null)
            {
                _items = null;
            }
            else
            {
                _items = new List <object>(icg._items.Count);
                foreach (object item in icg._items)
                {
                    _items.Add(copyManager.GetCopy(item));
                }
            }
            _populatedStartIndex = icg._populatedStartIndex;
            _populatedEndIndex   = icg._populatedEndIndex;
            if (icg._materializedItems == null)
            {
                _materializedItems = null;
            }
            else
            {
                _materializedItems = new List <FrameworkElement>(icg._materializedItems.Count);
                foreach (FrameworkElement item in icg._materializedItems)
                {
                    _materializedItems.Add(copyManager.GetCopy(item));
                }
            }
            if (icg._materializedGroupHeaders == null)
            {
                _materializedGroupHeaders = null;
            }
            else
            {
                _materializedGroupHeaders = new HeaderItemWrapper[icg._materializedGroupHeaders.Length];
                for (int n = 0; n < icg._materializedGroupHeaders.Length; ++n)
                {
                    _materializedGroupHeaders[n] = copyManager.GetCopy(icg._materializedGroupHeaders[n]);
                }
            }
        }
Exemplo n.º 3
0
    protected virtual void PrepareItemsOverride(bool force)
    {
      if (_panelTemplateApplied && _itemsHostPanel != null && !force)
        return;
      // Check properties which are necessary in each case
      if (ItemsPanel == null)
        return;

      ItemsPresenter presenter = FindItemsPresenter();
      if (presenter == null)
        return;

      if (!_panelTemplateApplied)
      {
        _panelTemplateApplied = true;
        presenter.ApplyTemplate(ItemsPanel);
        _itemsHostPanel = null;
      }

      if (_itemsHostPanel == null)
        _itemsHostPanel = presenter.ItemsHostPanel;
      if (_itemsHostPanel == null)
        return;

      // Albert: We cannot exit the method if one of the styles is not set because the styles
      // might be found by the SkinEngine's automatic Style assignment (FrameworkElement.CopyDefaultStyle)
      //if (ItemContainerStyle == null || ItemTemplate == null)
      //  return;

      IEnumerable itemsSource = ItemsSource;
      if (itemsSource == null)
      { // In this case, we must set up the items control using the Items property
        ItemCollection items = _items;
        ItemCollection preparedChildren = new ItemCollection();
        bool setItems = false;
        if (items == null)
        {
          // Restore items from "ItemsSource mode" where they have been set to null
          items = new ItemCollection();
          setItems = true;
        }
        foreach (object item in items)
        {
          object itemCopy = MpfCopyManager.DeepCopyWithFixedObject(item, this); // Keep this object as LogicalParent
          FrameworkElement element = itemCopy as FrameworkElement ?? PrepareItemContainer(itemCopy);
          if (element.Style == null && element is ContentControl)
            element.Style = ItemContainerStyle;
          element.LogicalParent = this;
          preparedChildren.Add(element);
        }
        presenter.SetDataStrings(BuildDataStrings(items));

        SetPreparedItems(setItems, setItems ? items : null, true, preparedChildren);
      }
      else
      {
        IList<object> l = new List<object>();
        ISynchronizable sync = itemsSource as ISynchronizable;
        if (sync != null)
          lock (sync.SyncRoot)
            CollectionUtils.AddAll(l, itemsSource);
        else
          CollectionUtils.AddAll(l, itemsSource);

        presenter.SetDataStrings(BuildDataStrings(l));

        VirtualizingStackPanel vsp = _itemsHostPanel as VirtualizingStackPanel;
        if (vsp != null)
        {
          // In this case, the VSP will generate its items by itself
          ListViewItemGenerator lvig = new ListViewItemGenerator();
          lvig.Initialize(this, l, ItemContainerStyle, ItemTemplate);
          SimplePropertyDataDescriptor dd;
          if (SimplePropertyDataDescriptor.CreateSimplePropertyDataDescriptor(this, "IsEmpty", out dd))
            SetValueInRenderThread(dd, l.Count == 0);
          vsp.SetItemProvider(lvig);

          SetPreparedItems(true, null, false, null);
        }
        else
        {
          ItemCollection preparedItems = new ItemCollection();
          preparedItems.AddAll(l.Select(PrepareItemContainer));

          SetPreparedItems(true, null, true, preparedItems);
        }
      }
    }
Exemplo n.º 4
0
    protected virtual void PrepareItemsOverride(bool force)
    {
      if (_panelTemplateApplied && _itemsHostPanel != null && !force)
        return;
      // Check properties which are necessary in each case
      if (ItemsPanel == null)
        return;

      ItemsPresenter presenter = FindItemsPresenter();
      if (presenter == null)
        return;

      if (!_panelTemplateApplied)
      {
        _panelTemplateApplied = true;
        presenter.ApplyTemplate(ItemsPanel);
        _itemsHostPanel = null;
      }

      if (_itemsHostPanel == null)
        _itemsHostPanel = presenter.ItemsHostPanel;
      if (_itemsHostPanel == null)
        return;

      IEnumerable itemsSource = ItemsSource;
      if (itemsSource == null)
      { // In this case, we must set up the items control using the Items property
        ItemCollection items = _items;
        ItemCollection preparedChildren = new ItemCollection();
        bool setItems = false;
        if (items == null)
        {
          // Restore items from "ItemsSource mode" where they have been set to null
          items = new ItemCollection();
          setItems = true;
        }
        foreach (object item in items)
        {
          object itemCopy = MpfCopyManager.DeepCopyWithFixedObject(item, this); // Keep this object as LogicalParent
          FrameworkElement element = itemCopy as FrameworkElement ?? PrepareItemContainer(itemCopy);
          if (element.Style == null)
            element.Style = ItemContainerStyle;
          element.LogicalParent = this;
          preparedChildren.Add(element);
        }
        presenter.SetDataStrings(BuildDataStrings(items));

        SetPreparedItems(setItems, setItems ? items : null, true, preparedChildren);
      }
      else
      {
        IList<object> l = new List<object>();
        ISynchronizable sync = itemsSource as ISynchronizable;
        if (sync != null)
          lock (sync.SyncRoot)
            CollectionUtils.AddAll(l, itemsSource);
        else
          CollectionUtils.AddAll(l, itemsSource);

        presenter.SetDataStrings(BuildDataStrings(l));

        VirtualizingStackPanel vsp = _itemsHostPanel as VirtualizingStackPanel;
        if (vsp != null)
        {
          // In this case, the VSP will generate its items by itself
          ListViewItemGenerator lvig = new ListViewItemGenerator();
          lvig.Initialize(this, l, ItemContainerStyle, ItemTemplate);
          IsEmpty = l.Count == 0;
          vsp.SetItemProvider(lvig);

          SetPreparedItems(true, null, false, null);
        }
        else
        {
          ItemCollection preparedItems = new ItemCollection();
          preparedItems.AddAll(l.Select(PrepareItemContainer));

          SetPreparedItems(true, null, true, preparedItems);
        }
      }
    }
Exemplo n.º 5
0
        protected virtual void PrepareItemsOverride(bool force)
        {
            if (_panelTemplateApplied && _itemsHostPanel != null && !force)
            {
                return;
            }
            // Check properties which are necessary in each case
            if (ItemsPanel == null)
            {
                return;
            }

            ItemsPresenter presenter = FindItemsPresenter();

            if (presenter == null)
            {
                return;
            }

            if (!_panelTemplateApplied)
            {
                _panelTemplateApplied = true;
                presenter.ApplyTemplate(ItemsPanel);
                _itemsHostPanel = null;
            }

            if (_itemsHostPanel == null)
            {
                _itemsHostPanel = presenter.ItemsHostPanel;
            }
            if (_itemsHostPanel == null)
            {
                return;
            }

            IEnumerable itemsSource = ItemsSource;

            if (itemsSource == null)
            { // In this case, we must set up the items control using the Items property
                ItemCollection items            = _items;
                ItemCollection preparedChildren = new ItemCollection();
                bool           setItems         = false;
                if (items == null)
                {
                    // Restore items from "ItemsSource mode" where they have been set to null
                    items    = new ItemCollection();
                    setItems = true;
                }
                foreach (object item in items)
                {
                    object           itemCopy = MpfCopyManager.DeepCopyWithFixedObject(item, this); // Keep this object as LogicalParent
                    FrameworkElement element  = itemCopy as FrameworkElement ?? PrepareItemContainer(itemCopy);
                    if (element.Style == null)
                    {
                        element.Style = ItemContainerStyle;
                    }
                    element.LogicalParent = this;
                    preparedChildren.Add(element);
                }
                presenter.SetDataStrings(BuildDataStrings(items));

                SetPreparedItems(setItems, setItems ? items : null, true, preparedChildren);
            }
            else
            {
                IList <object>  l    = new List <object>();
                ISynchronizable sync = itemsSource as ISynchronizable;
                if (sync != null)
                {
                    lock (sync.SyncRoot)
                        CollectionUtils.AddAll(l, itemsSource);
                }
                else
                {
                    CollectionUtils.AddAll(l, itemsSource);
                }

                presenter.SetDataStrings(BuildDataStrings(l));

                VirtualizingStackPanel vsp = _itemsHostPanel as VirtualizingStackPanel;
                if (vsp != null)
                {
                    // In this case, the VSP will generate its items by itself
                    ListViewItemGenerator lvig = new ListViewItemGenerator();
                    lvig.Initialize(this, l, ItemContainerStyle, ItemTemplate);
                    IsEmpty = l.Count == 0;
                    vsp.SetItemProvider(lvig);

                    SetPreparedItems(true, null, false, null);
                }
                else
                {
                    ItemCollection preparedItems = new ItemCollection();
                    preparedItems.AddAll(l.Select(PrepareItemContainer));

                    SetPreparedItems(true, null, true, preparedItems);
                }
            }
        }
Exemplo n.º 6
0
        protected virtual void PrepareItemsOverride(bool force)
        {
            if (_panelTemplateApplied && _itemsHostPanel != null && !force)
            {
                return;
            }
            // Check properties which are necessary in each case
            if (ItemsPanel == null)
            {
                return;
            }

            ItemsPresenter presenter = FindItemsPresenter();

            if (presenter == null)
            {
                return;
            }

            if (!_panelTemplateApplied)
            {
                _panelTemplateApplied = true;
                presenter.ApplyTemplate(ItemsPanel);
                _itemsHostPanel = null;
            }

            if (_itemsHostPanel == null)
            {
                _itemsHostPanel = presenter.ItemsHostPanel;
            }
            if (_itemsHostPanel == null)
            {
                return;
            }

            // Albert: We cannot exit the method if one of the styles is not set because the styles
            // might be found by the SkinEngine's automatic Style assignment (FrameworkElement.CopyDefaultStyle)
            //if (ItemContainerStyle == null || ItemTemplate == null)
            //  return;

            IEnumerable itemsSource = ItemsSource;

            if (itemsSource == null)
            { // In this case, we must set up the items control using the Items property
                ItemCollection items            = _items;
                ItemCollection preparedChildren = new ItemCollection();
                bool           setItems         = false;
                if (items == null)
                {
                    // Restore items from "ItemsSource mode" where they have been set to null
                    items    = new ItemCollection();
                    setItems = true;
                }
                foreach (object item in items)
                {
                    object           itemCopy = MpfCopyManager.DeepCopyWithFixedObject(item, this); // Keep this object as LogicalParent
                    FrameworkElement element  = itemCopy as FrameworkElement ?? PrepareItemContainer(itemCopy);
                    if (element.Style == null && element is ContentControl)
                    {
                        element.Style = ItemContainerStyle;
                    }
                    element.LogicalParent = this;
                    preparedChildren.Add(element);
                }
                presenter.SetDataStrings(BuildDataStrings(items));

                SetPreparedItems(setItems, setItems ? items : null, true, preparedChildren);
            }
            else
            {
                IList <object>  l    = new List <object>();
                ISynchronizable sync = itemsSource as ISynchronizable;
                if (sync != null)
                {
                    lock (sync.SyncRoot)
                        CollectionUtils.AddAll(l, itemsSource);
                }
                else
                {
                    CollectionUtils.AddAll(l, itemsSource);
                }

                presenter.SetDataStrings(BuildDataStrings(l));

                var vsp = _itemsHostPanel as IVirtualizingPanel;
                if (vsp != null)
                {
                    // In this case, the VSP will generate its items by itself
                    ListViewItemGenerator lvig = new ListViewItemGenerator();
                    lvig.Initialize(this, l, ItemContainerStyle, ItemTemplate,
                                    GroupingValueProvider, GroupingBindingWrapper == null ? null :  GroupingBindingWrapper.Binding, GroupHeaderContainerStyle, GroupHeaderTemplate);
                    SimplePropertyDataDescriptor dd;
                    if (SimplePropertyDataDescriptor.CreateSimplePropertyDataDescriptor(this, "IsEmpty", out dd))
                    {
                        SetValueInRenderThread(dd, l.Count == 0);
                    }
                    vsp.SetItemProvider(lvig);

                    SetPreparedItems(true, null, false, null);
                }
                else
                {
                    ItemCollection preparedItems = new ItemCollection();
                    preparedItems.AddAll(l.Select(PrepareItemContainer));

                    SetPreparedItems(true, null, true, preparedItems);
                }
            }
        }