Beispiel #1
0
        /// <summary>
        /// 移除 TabItem 方法
        /// </summary>
        /// <param name="item"></param>
        public virtual Task Remove(TabItem item)
        {
            var index = _items.IndexOf(item);

            _items.Remove(item);
            var activeItem = _items.FirstOrDefault(i => i.IsActive);

            if (activeItem == null)
            {
                // 删除的 TabItem 是当前 Tab
                if (index < _items.Count)
                {
                    // 查找后面的 Tab
                    activeItem = _items[index];
                }
                else
                {
                    // 查找前面的 Tab
                    activeItem = _items.LastOrDefault();
                }
                if (activeItem != null)
                {
                    activeItem.SetActive(true);
                }
            }
            TabContent?.Render();
            return(Task.CompletedTask);
        }
Beispiel #2
0
 /// <summary>
 /// 设置指定 TabItem 为激活状态
 /// </summary>
 /// <param name="item"></param>
 public virtual Task ActiveTab(TabItem item)
 {
     _items.ForEach(i => i.SetActive(false));
     item.SetActive(true);
     TabHeader?.Render();
     TabContent?.Render();
     return(Task.CompletedTask);
 }
Beispiel #3
0
 /// <summary>
 /// 点击 TabItem 时回调此方法
 /// </summary>
 /// <param name="item"></param>
 protected virtual void OnTabClick(TabItem item)
 {
     foreach (var tab in Items)
     {
         var isActive = tab.Text == item.Text;
         tab.SetActive(isActive);
     }
     TabContent?.Render(item);
 }
Beispiel #4
0
        /// <summary>
        /// 添加 TabItem 方法
        /// </summary>
        /// <param name="item"></param>
        public virtual Task Add(TabItem item)
        {
            var check = _items.Contains(item);

            if (item.IsActive || !check)
            {
                _items.ForEach(i => i.SetActive(false));
            }
            if (!check)
            {
                _items.Add(item);
                item.SetActive(true);
            }

            TabHeader?.Render();
            TabContent?.Render();
            return(Task.CompletedTask);
        }
Beispiel #5
0
        /// <summary>
        /// 移除 TabItem 方法
        /// </summary>
        /// <param name="item"></param>
        public virtual void Remove(TabItem item)
        {
            _items.Remove(item);
            var activeItem = _items.FirstOrDefault(i => i.IsActive);

            if (activeItem == null)
            {
                activeItem = _items.LastOrDefault();
                if (activeItem != null)
                {
                    activeItem.SetActive(true);
                    OnTabClick(activeItem);
                }
                else
                {
                    // no TabItem
                    TabContent?.Clear();
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 点击下一个标签页时回调此方法
        /// </summary>
        protected virtual void ClickNextTab()
        {
            var item = Items.FirstOrDefault(i => i.IsActive);

            if (item != null)
            {
                var index = _items.IndexOf(item);
                if (index < _items.Count)
                {
                    item.SetActive(false);
                    index++;
                    if (index + 1 > _items.Count)
                    {
                        index = 0;
                    }
                    item = Items.ElementAt(index);
                    item.SetActive(true);
                    TabContent?.Render();
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 点击上一个标签页时回调此方法
        /// </summary>
        protected virtual void ClickPrevTab()
        {
            var item = Items.FirstOrDefault(i => i.IsActive);

            if (item != null)
            {
                var index = _items.IndexOf(item);
                if (index > -1)
                {
                    item.SetActive(false);
                    index--;
                    if (index < 0)
                    {
                        index = _items.Count - 1;
                    }
                    item = Items.ElementAt(index);
                    item.SetActive(true);
                    TabContent?.Render();
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// 点击 TabItem 时回调此方法
 /// </summary>
 protected virtual Task OnClickTab()
 {
     TabContent?.Render();
     return(Task.CompletedTask);
 }
Beispiel #9
0
 /// <summary>
 /// 点击 TabItem 时回调此方法
 /// </summary>
 protected virtual async Task OnClickTabItem(TabItem item)
 {
     TabContent?.Render();
     await OnClickTab.Invoke(item);
 }