我有一個TabControl與自定義TabItem。視圖xaml看起來像這樣。WPF自定義TabItem在restyle上消失了嗎?
<UserControl x:Class="PeripheryModule.Views.MainTabView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:PeripheryModule.Controls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TabControl>
<TabItem Header="TabItem 4" />
<local:CustomTabItem Header="Testing" />
</TabControl>
</Grid>
</UserControl>
的CustomTabItem.xaml文件看起來像這樣
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PeripheryModule.Controls">
<Style TargetType="{x:Type local:CustomTabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomTabItem}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
和CustomTabItem.xaml.cs文件看起來像這樣
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace PeripheryModule.Controls
{
public class CustomTabItem : TabItem
{
static CustomTabItem()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomTabItem), new FrameworkPropertyMetadata(typeof(CustomTabItem)));
}
}
}
我沒有得到任何引發的錯誤,所發生的只是tabItem根本不顯示。但是,如果我將CustomTabItem.aspx.cs中的DefaultStyleKeyProperty
行註釋掉,它會顯示出來。
無論如何,我可能已經設置了錯誤。最終目標是擁有可關閉的標籤。