2012-08-28 67 views
1

我有以下TabItem刪除浮雕風格(說「的TabItem」,其實我的意思是按鈕激活選項卡):上禁用的TabItem

<TabItem RequestBringIntoView="activateTab_Click" Name="tabImplantation" Width="270" Height="138" BorderBrush="{x:Null}" IsEnabled="False" Foreground="#FF075C81"> 
    <TabItem.Header> 
     <StackPanel Orientation="Horizontal"> 
      <Image Width="148" Margin="-5,0,0,0" VerticalAlignment="Stretch" Name="implantation_pic" Source="/project;component/Images/implantation_a.jpg" /> 
     </StackPanel> 
    </TabItem.Header> 
    ... 
</TabItem> 

正如你看到的,這是一個定製的TabItem其中有一個Image對象。我已經通過設置BorderBrush="{x:Null}"刪除了邊框,並且效果很好。但是,如果它被禁用(IsEnabled="False"),它呈現某種內部浮雕陰影或類似的東西(也可能是一個邊框,我不知道這一點)。

如何在沒有這個邊框的情況下渲染它,以防它被禁用?另請參閱下面的圖片。提前致謝!

請注意,我不是C#專家,我只是在做一些重新設置。該計劃本身的發展是外包的。

The TabItem is enabled and renders correctly

The TabItem is disabled and renders a border

回答

2

要達到你要你要編輯的樣子TabItemControlTemplate(這是很容易使用混合做的)。

控件禁用時沒有呈現「內部浮雕陰影」,這可能是邊框效果。下面是禁用的邊界時IsEnabled = false(添加到您的Window.ResourcesApplication.Resources)的ControlTemplate的編輯版本:

<Style x:Key="TabItemFocusVisual"> 
     <Setter Property="Control.Template"> 
      <Setter.Value> 
       <ControlTemplate> 
        <Rectangle Margin="3,3,3,1" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
    <SolidColorBrush x:Key="TabControlNormalBorderBrush" Color="#8C8E94"/> 
    <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0"> 
     <GradientStop Color="#F3F3F3" Offset="0"/> 
     <GradientStop Color="#EBEBEB" Offset="0.5"/> 
     <GradientStop Color="#DDDDDD" Offset="0.5"/> 
     <GradientStop Color="#CDCDCD" Offset="1"/> 
    </LinearGradientBrush> 
    <LinearGradientBrush x:Key="TabItemHotBackground" EndPoint="0,1" StartPoint="0,0"> 
     <GradientStop Color="#EAF6FD" Offset="0.15"/> 
     <GradientStop Color="#D9F0FC" Offset=".5"/> 
     <GradientStop Color="#BEE6FD" Offset=".5"/> 
     <GradientStop Color="#A7D9F5" Offset="1"/> 
    </LinearGradientBrush> 
    <SolidColorBrush x:Key="TabItemSelectedBackground" Color="#F9F9F9"/> 
    <SolidColorBrush x:Key="TabItemHotBorderBrush" Color="#3C7FB1"/> 
    <SolidColorBrush x:Key="TabItemDisabledBackground" Color="#F4F4F4"/> 
    <SolidColorBrush x:Key="TabItemDisabledBorderBrush" Color="#FFC9C7BA"/> 
    <Style TargetType="{x:Type TabItem}"> 
     <Setter Property="FocusVisualStyle" Value="{StaticResource TabItemFocusVisual}"/> 
     <Setter Property="Foreground" Value="Black"/> 
     <Setter Property="Padding" Value="6,1,6,1"/> 
     <Setter Property="BorderBrush" Value="{StaticResource TabControlNormalBorderBrush}"/> 
     <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/> 
     <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
     <Setter Property="VerticalContentAlignment" Value="Stretch"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type TabItem}"> 
        <Grid SnapsToDevicePixels="true"> 
         <!--previous (default) border brush value was BorderBrush="{TemplateBinding BorderBrush}"--> 
         <Border x:Name="Bd" BorderBrush="{x:Null}" BorderThickness="1,1,1,0" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"> 
          <ContentPresenter x:Name="Content" ContentSource="Header" HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
         </Border> 
        </Grid> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsMouseOver" Value="true"> 
          <Setter Property="Background" TargetName="Bd" Value="{StaticResource TabItemHotBackground}"/> 
         </Trigger> 
         <Trigger Property="IsSelected" Value="true"> 
          <Setter Property="Panel.ZIndex" Value="1"/> 
          <Setter Property="Background" TargetName="Bd" Value="{StaticResource TabItemSelectedBackground}"/> 
         </Trigger> 
         <MultiTrigger> 
          <MultiTrigger.Conditions> 
           <Condition Property="IsSelected" Value="false"/> 
           <Condition Property="IsMouseOver" Value="true"/> 
          </MultiTrigger.Conditions> 
          <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource TabItemHotBorderBrush}"/> 

         </MultiTrigger> 
         <Trigger Property="TabStripPlacement" Value="Bottom"> 
          <Setter Property="BorderThickness" TargetName="Bd" Value="1,0,1,1"/> 
         </Trigger> 
         <Trigger Property="TabStripPlacement" Value="Left"> 
          <Setter Property="BorderThickness" TargetName="Bd" Value="1,1,0,1"/> 
         </Trigger> 
         <Trigger Property="TabStripPlacement" Value="Right"> 
          <Setter Property="BorderThickness" TargetName="Bd" Value="0,1,1,1"/> 
         </Trigger> 
         <MultiTrigger> 
          <MultiTrigger.Conditions> 
           <Condition Property="IsSelected" Value="true"/> 
           <Condition Property="TabStripPlacement" Value="Top"/> 
          </MultiTrigger.Conditions> 
          <Setter Property="Margin" Value="-2,-2,-2,-1"/> 
          <Setter Property="Margin" TargetName="Content" Value="0,0,0,1"/> 
         </MultiTrigger> 
         <MultiTrigger> 
          <MultiTrigger.Conditions> 
           <Condition Property="IsSelected" Value="true"/> 
           <Condition Property="TabStripPlacement" Value="Bottom"/> 
          </MultiTrigger.Conditions> 
          <Setter Property="Margin" Value="-2,-1,-2,-2"/> 
          <Setter Property="Margin" TargetName="Content" Value="0,1,0,0"/> 
         </MultiTrigger> 
         <MultiTrigger> 
          <MultiTrigger.Conditions> 
           <Condition Property="IsSelected" Value="true"/> 
           <Condition Property="TabStripPlacement" Value="Left"/> 
          </MultiTrigger.Conditions> 
          <Setter Property="Margin" Value="-2,-2,-1,-2"/> 
          <Setter Property="Margin" TargetName="Content" Value="0,0,1,0"/> 
         </MultiTrigger> 
         <MultiTrigger> 
          <MultiTrigger.Conditions> 
           <Condition Property="IsSelected" Value="true"/> 
           <Condition Property="TabStripPlacement" Value="Right"/> 
          </MultiTrigger.Conditions> 
          <Setter Property="Margin" Value="-1,-2,-2,-2"/> 
          <Setter Property="Margin" TargetName="Content" Value="1,0,0,0"/> 
         </MultiTrigger> 
         <Trigger Property="IsEnabled" Value="false"> 
          <!--previous (default) border brush value was BorderBrush="{StaticResource TabItemDisabledBorderBrush}"--> 
          <Setter Property="BorderBrush" TargetName="Bd" Value="{x:Null}" /> 
          <Setter Property="Background" TargetName="Bd" Value="{StaticResource TabItemDisabledBackground}"/> 
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

這裏的控制將如何看起來像應用樣式的變化(預覽在Blend + SketchFlow的爲VS2012後):

Preview in Blend + SketchFlow for VS2012

+1

我會給你一個cookie,如果我可以,謝謝! –