简体   繁体   中英

WPF Styling setter's targetname to dependencyproperty's property

I am trying to set the targetname of a style setter to a dependency property's Name property. Not quite sure how to approach this.

 //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}" 

Basically in the TargetName I would like to put the name of the object that LabelToDisplay property references.

Maybe you can move that Opacity setter into LabelToDisplay object and trigger it only when needed?

Maybe you can bind against LabelToDisplay in TargetName?

If not, there is last option I think, you'll make new DataTrigger against LabelToDisplay, and then you do:

<DataTrigger.EnterActions>

    Animation here

</DataTrigger.EnterActions>

You can set Target with animation easily. (Eg you don't need "Name" property at all, just give the object it needs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM