0
我有以下的用户控件:WPF DataTrigger上的TabItem
<UserControl x:Class="WpfExample.Views.TabsUserControl"
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:v="clr-namespace:WpfExample.Views"
xmlns:vm="clr-namespace:WpfExample.ViewModels"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
DataContext="{Binding TabsViewModel, Source={StaticResource Locator}}">
<TabControl ItemsSource="{Binding Tabs}"
SelectedItem="{Binding SelectedTabViewModel}">
<TabControl.Resources>
<DataTemplate DataType="{x:Type vm:ViewDatabaseTableViewModel}">
<v:ViewDatabaseTableUserControl />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:CustomerViewModel}">
<v:CustomerView />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:SystemSetupViewModel}">
<v:SystemSetupUserControl />
</DataTemplate>
</TabControl.Resources>
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="{Binding Header}" />
<Setter Property="Width" Value="120" />
<!--<Setter Property="IsEnabled" Value="False" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ProductIsLicensed}" />
<Trigger Property="{Binding Header}" Value="System Setup">
<Setter Property="IsEnabled" Value="True" />
</Trigger>
</Style.Triggers>-->
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</UserControl>
我想用一个DataTrigger启用/基于wheter或没有在产品获得许可禁用标签。我想这可能工作(在<TabControl>
块中添加的):
<ControlTemplate TargetType="TabItem">
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ProductIsLicensed}" Value="False">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
但它给我“型‘System.Windows.Markup.XamlParseException’发生在PresentationFramework.dll的第一个机会异常”的一个例外。
如果ProductIsLicensed
的值为False,有人能告诉我如何完成标签的禁用吗?
你把ControlTemplate放在一个样式里面吗? – sondergard 2014-09-10 20:59:29