2013-04-16 203 views
1

我一直兜兜轉轉該數據觸發因此它是不工作...如何從父屬性設置觸發設置子屬性

我有了一個默認的陰影效果邊框的按鈕。不過,我想創建一個dep屬性來切換這個。然而,我從來沒有達到設定效果的地步。

<Style x:Key="RoundedButton" TargetType="{x:Type Button}"> 
<Setter Property="Template"> 
<Setter.Value> 
    <ControlTemplate TargetType="ctrls:RoundedButton"> 
    <Grid> 
    <Border> 
    <Border.Style> 
     <Style TargetType="ctrls:RoundedButton"> 
     <Style.Triggers> 
     <Trigger Property="IsDropShadowVisible" Value="True"> 
     <Setter Property="Effect"> 
      <Setter.Value> 
      <DropShadowEffect ShadowDepth="1"/> 
      </Setter.Value> 
     </Setter> 
     </Trigger> 
     </Style.Triggers> 
     </Style> 
    </Border.Style> 

這是基於關閉按鈕,但實現自定義用戶控制......這是遺留代碼...

+0

後全XAML。另外,那個'DataTrigger'沒有意義。使用常規的'Trigger Property = IsDropShadowVisible .. etc ..'。 –

+0

@HighCore更新了我的回答 –

+0

您的XAML沒有意義。你有一個'Style TargetType =「Button」',然後是'ControlTemplate TargetType =「ctrls:RoundedButton」'。我建議你看看[本教程](http://www.wpftutorial.net)介紹性的XAML內容。 –

回答

1

我這裏 這篇在一個新的WPF窗口的作品是什麼。沒有比你在這裏看到的其他代碼隱藏。

<Window.Resources> 
    <Style TargetType="{x:Type local:ShadowButton}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type local:ShadowButton}"> 
        <Button Name="Button"></Button> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsDropShadowVisible" Value="True"> 
          <Setter TargetName="Button" Property="Effect"> 
           <Setter.Value> 
            <DropShadowEffect ShadowDepth="1"/> 
           </Setter.Value> 
          </Setter> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</Window.Resources> 

<!-- snip code --> 

<local:ShadowButton Height="10" Width="10" IsDropShadowVisible="true"/> 

代碼隱藏:

public class ShadowButton : Button 
{ 
    public DependencyProperty IsDropShadowVisibleProperty = 
     DependencyProperty.Register("IsDropShadowVisible", typeof(Boolean), typeof(ShadowButton), new PropertyMetadata(false)); 
    public Boolean IsDropShadowVisible 
    { 
     get { return (Boolean)GetValue(IsDropShadowVisibleProperty); } 
     set { SetValue(IsDropShadowVisibleProperty, value); } 
    } 
} 
+0

如果考慮到這個評論,那麼這個修正了我的問題:邊框樣式,命名邊框,然後給setter這個targetname。完成。 –