2013-04-07 82 views
0

我有以下Checkbox.xaml文件。我想在CheckBox上應用兩種不同的Dropshadow效果。所以我採取了兩個MultiTriggers。我想刪除那些MultiTriggers並將它們組合爲使用DataBindingBackgroundBorder元素的單個觸發器。因爲Border元素將因我應用的第一個觸發器而始終具有正確的背景。綁定背景到模板控件

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 

    <ResourceDictionary.MergedDictionaries> 
     <ResourceDictionary Source="..\Colors\Colors.xaml"></ResourceDictionary> 
    </ResourceDictionary.MergedDictionaries> 

    <ControlTemplate x:Key="CheckBoxTemplate" TargetType="CheckBox" > 

     <BulletDecorator > 
     <BulletDecorator.Bullet> 
      <Border x:Name="Border" 
       Width="13" 
       Height="13" 
       CornerRadius="0" 
       Background="{StaticResource TextNormalBrush}" 
       BorderThickness="3" 
       BorderBrush="Black"> 
       </Border> 
     </BulletDecorator.Bullet> 
     <ContentPresenter Margin="4,0,0,0" 
      VerticalAlignment="Center" 
      HorizontalAlignment="Left" 
      RecognizesAccessKey="True" /> 
     </BulletDecorator> 

     <ControlTemplate.Triggers> 
      <Trigger Property="IsChecked" Value="True"> 
       <Setter TargetName="Border" Property="Background" Value="{StaticResource AlternateLinearBrush}"/> 
      </Trigger> 
      <MultiTrigger> 
       <MultiTrigger.Conditions> 
        <Condition Property="IsMouseOver" Value="True"></Condition> 
        <Condition Property="IsChecked" Value="False"></Condition> 
       </MultiTrigger.Conditions> 
       <MultiTrigger.Setters> 
        <Setter TargetName="Border" Property="Effect"> 
         <Setter.Value> 
          <DropShadowEffect ShadowDepth="0" Direction="0" BlurRadius="15" Opacity="1" Color="{StaticResource TextNormalColor }"> 

          </DropShadowEffect> 
         </Setter.Value> 
        </Setter> 

       </MultiTrigger.Setters> 
      </MultiTrigger> 

      <MultiTrigger> 
       <MultiTrigger.Conditions> 
        <Condition Property="IsMouseOver" Value="True"></Condition> 
        <Condition Property="IsChecked" Value="True"></Condition> 
       </MultiTrigger.Conditions> 
       <MultiTrigger.Setters> 
        <Setter TargetName="Border" Property="Effect"> 
         <Setter.Value> 
          <DropShadowEffect ShadowDepth="0" Direction="0" BlurRadius="15" Opacity="1" Color="{StaticResource AlternateColor }"> 

          </DropShadowEffect> 
         </Setter.Value> 
        </Setter> 

       </MultiTrigger.Setters> 
      </MultiTrigger>     
     </ControlTemplate.Triggers>    
    </ControlTemplate> 

    <Style x:Key="CheckBoxStyle" TargetType="{x:Type CheckBox}"> 
     <Setter Property="Template" Value="{StaticResource CheckBoxTemplate}" /> 
     <Setter Property="Foreground" Value="{StaticResource TextNormalBrush}" /> 
     <Setter Property="TextOptions.TextHintingMode" Value="Animated"/> 

    </Style> 
</ResourceDictionary> 
+0

你的問題是什麼? – Bernard 2013-04-07 13:44:55

+0

我想用DataBinding背景來訪問觸發器中的'Border'元素的背景。 – 2013-04-07 13:48:03

+0

我很困惑。你想通過'MultiTrigger'實現兩個不同的DropShadow效果。現在你想修改* Border *的背景,因爲某些原因。我不明白爲什麼。有點混淆整個事情。你能解釋一下嗎,這樣我可以提供一個解決方案嗎? – DHN 2013-04-07 13:56:48

回答

0

你的意思是一樣的財產以後:

 <Trigger Property="IsMouseOver" Value="True"> 
       <Setter TargetName="Border" Property="Effect"> 
        <Setter.Value> 
         <DropShadowEffect ShadowDepth="0" Direction="0" BlurRadius="15" Opacity="1" Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=Background.Color}"> 
         </DropShadowEffect> 
        </Setter.Value> 
       </Setter> 
     </Trigger> 

在這個例子中,暗影Effact始終有其邊框的背景色。