2012-09-07 68 views
0

我試圖將樣式設置器的targetname設置爲依賴屬性的Name屬性。不太確定如何解決這個問題。WPF樣式設置者的目標名稱爲dependencyproperty的屬性

//Customcontrol's Generic.xaml 
<Style TargetType="{x:Type Controls:MyControl}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Controls:MyControl}"> 
       <Border Background="{TemplateBinding Background}" 
         BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}"> 
        <ContentControl Content="{TemplateBinding Content}"/> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    <Setter TargetName="WHAT SHOULD I PUT HERE" Property="Opacity" Value="0.75"/> 

</Style> 

// Dependency Property 
public static readonly DependencyProperty LabelToDisplayProperty ... 

// In XAML that adds the custom control 
LabelToDisplay="{x:Reference Name=TitleLabel}" 

基本上在TargetName我希望把對象的nameLabelToDisplay屬性引用。

回答

0

也許你可以將該不透明度設置器移動到LabelToDisplay對象中並僅在需要時觸發它?

也許你可以綁定在TargetName中的LabelToDisplay?

如果不是,還有最後一個選擇,我認爲,你會做出對LabelToDisplay新DataTrigger,然後你做:

<DataTrigger.EnterActions> 

    Animation here 

</DataTrigger.EnterActions> 

您可以通過動畫輕鬆設定目標。 (例如,根本不需要「名稱」屬性,只需給它所需的對象)

相關問題