当前位置: 首页>>代码示例>>C#>>正文


C# ItemCollection.AddAll方法代码示例

本文整理汇总了C#中ItemCollection.AddAll方法的典型用法代码示例。如果您正苦于以下问题:C# ItemCollection.AddAll方法的具体用法?C# ItemCollection.AddAll怎么用?C# ItemCollection.AddAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ItemCollection的用法示例。


在下文中一共展示了ItemCollection.AddAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrepareItemsOverride

    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);
        }
      }
    }
开发者ID:VicDemented,项目名称:MediaPortal-2,代码行数:88,代码来源:ItemsControl.cs

示例2: PrepareItemsOverride

    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);
        }
      }
    }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:81,代码来源:ItemsControl.cs


注:本文中的ItemCollection.AddAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。