xml
复制代码
<hc:TabControl
Name="TabControl"
Grid.Row="0"
Background="{StaticResource TitleBackground}"
BorderBrush="#111"
BorderThickness="0"
IsScrollable="True"
ItemsSource="{Binding PageInfoList}"
SelectedIndex="{Binding ChannelIndex}"
ShowContextMenu="False"
TabItemWidth="100">
<hc:TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}" />
</DataTemplate>
</hc:TabControl.ItemTemplate>
<hc:TabControl.ContentTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Content, Mode=OneTime}" />
</DataTemplate>
</hc:TabControl.ContentTemplate>
<!-- 在此位置绑定IsEnabled属性 -->
<hc:TabControl.ItemContainerStyle>
<Style TargetType="hc:TabItem">
<Style.Triggers>
<DataTrigger Binding="{Binding IsTabEnabled}" Value="False">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</hc:TabControl.ItemContainerStyle>
</hc:TabControl>
csharp
复制代码
public partial class PageInfo : ObservableObject
{
[ObservableProperty]
public string header;
[ObservableProperty]
public bool isTabEnabled;
[ObservableProperty]
public FrameworkElement content;
}