csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="TabStrip.cs" company="Steven Kirk">
|
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
using Perspex.Input;
|
|
|
|
namespace Perspex.Controls
|
|
{
|
|
public class TabStrip : ItemsControl
|
|
{
|
|
private static readonly ItemsPanelTemplate PanelTemplate = new ItemsPanelTemplate(
|
|
() => new StackPanel());
|
|
|
|
private static readonly DataTemplate TabTemplate = new DataTemplate(
|
|
o => new TabItem { Content = o });
|
|
|
|
static TabStrip()
|
|
{
|
|
ItemsPanelProperty.OverrideDefaultValue(typeof(TabStrip), PanelTemplate);
|
|
ItemTemplateProperty.OverrideDefaultValue(typeof(TabStrip), TabTemplate);
|
|
}
|
|
|
|
public TabStrip()
|
|
{
|
|
this.PointerPressed += this.OnPointerPressed;
|
|
}
|
|
|
|
private void OnPointerPressed(object sender, PointerEventArgs e)
|
|
{
|
|
IVisual source = (IVisual)e.Source;
|
|
ContentPresenter presenter = source.GetVisualAncestor<ContentPresenter>();
|
|
|
|
if (presenter != null)
|
|
{
|
|
TabItem item = presenter.TemplatedParent as TabItem;
|
|
|
|
if (item != null && item.TemplatedParent == this)
|
|
{
|
|
item.IsSelected = true;
|
|
|
|
foreach (var i in item.GetVisualSiblings<TabItem>())
|
|
{
|
|
i.IsSelected = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|