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.
49 lines
1.5 KiB
49 lines
1.5 KiB
using Avalonia.Controls.Primitives;
|
|
|
|
namespace Avalonia.Controls.Generators
|
|
{
|
|
public class TabItemContainerGenerator : ItemContainerGenerator<TabItem>
|
|
{
|
|
public TabItemContainerGenerator(TabControl owner)
|
|
: base(owner, ContentControl.ContentProperty, ContentControl.ContentTemplateProperty)
|
|
{
|
|
Owner = owner;
|
|
}
|
|
|
|
public new TabControl Owner { get; }
|
|
|
|
protected override IControl CreateContainer(object item)
|
|
{
|
|
var tabItem = (TabItem)base.CreateContainer(item);
|
|
|
|
tabItem[~TabControl.TabStripPlacementProperty] = Owner[~TabControl.TabStripPlacementProperty];
|
|
|
|
if (tabItem.HeaderTemplate == null)
|
|
{
|
|
tabItem[~HeaderedContentControl.HeaderTemplateProperty] = Owner[~ItemsControl.ItemTemplateProperty];
|
|
}
|
|
|
|
if (tabItem.Header == null)
|
|
{
|
|
if (item is IHeadered headered)
|
|
{
|
|
tabItem.Header = headered.Header;
|
|
}
|
|
else
|
|
{
|
|
if (!(tabItem.DataContext is IControl))
|
|
{
|
|
tabItem.Header = tabItem.DataContext;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!(tabItem.Content is IControl))
|
|
{
|
|
tabItem[~ContentControl.ContentTemplateProperty] = Owner[~TabControl.ContentTemplateProperty];
|
|
}
|
|
|
|
return tabItem;
|
|
}
|
|
}
|
|
}
|
|
|