2014-09-10 2 views
0

에 나는 다음 UserControl을 가지고 : 나는/제품 허가 처리 여부 여부에 따라 해제 탭을 가능하게하는 DataTrigger를 사용하고자하는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> 

합니다. 나는 이것이합니다 (<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 값이 거짓 인 경우 누군가가 탭을 비활성화하는 방법을 알려주시겠습니까?

+0

ControlTemplate을 스타일 안에 넣었습니까? – sondergard

답변

0

트리거 또는 ControlTemplate이 필요하지 않으며, 이는 모든 기본 스타일을 망칠뿐입니다. 그냥 스타일을 만들어 스타일에 키를 제공하지 않음으로써 직접

<Style TargetType="TabItem"> 
    <Setter Property="IsEnabled" Path="{Binding IsProductLicensed}"/> 
</Style> 

의 IsEnabled를 결합, 사용자 컨트롤의 모든 TabItems에 적용됩니다.

ControlTemplate은 컨트롤의 모양과 느낌을 모두 정의하며 스타일 안의 Template 속성에만 적용 할 수 있습니다. 처음부터 컨트롤을 완전히 스타일링하려는 경우에만 사용해야합니다. 이 모양은 다음과 같습니다.

<Style TargetType="TabItem"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="TabItem"> 
       <!-- Define ALL here - look, effects, triggers etc. --> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style>