简体   繁体   English

WPF将设置程序的目标名称样式化为dependencyproperty的属性

[英]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. 我试图将样式设置器的targetname设置为依赖项属性的Name属性。 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. 基本上在TargetName我想放置LabelToDisplay属性引用的对象的name

Maybe you can move that Opacity setter into LabelToDisplay object and trigger it only when needed? 也许您可以将不透明度设置器移动到LabelToDisplay对象中,然后仅在需要时才触发它?

Maybe you can bind against LabelToDisplay in TargetName? 也许您可以在TargetName中绑定LabelToDisplay?

If not, there is last option I think, you'll make new DataTrigger against LabelToDisplay, and then you do: 如果没有,我认为有最后一个选择,您将针对LabelToDisplay进行新的DataTrigger,然后执行以下操作:

<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) (例如,您根本不需要“ Name”属性,只需提供所需的对象即可)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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