在ControlTemplate的触发器中,如何访问在ControlTemplate主体中定义的元素?
|
我有以下(简化的)ControlTemplate:
<ControlTemplate x:Key=\"ImageButtonTemplate\" TargetType=\"{x:Type controls:ImageButton}\">
<Grid x:Name=\"Grid\">
<Border [StuffRemoved]/>
<StackPanel [StuffRemoved]>
<Image [StuffRemoved] />
<ContentPresenter [StuffRemoved] />
</StackPanel>
<Grid.RenderTransform>
<ScaleTransform x:Name=\"ImgBtnScale\"/>
</Grid.RenderTransform>
</Grid>
<ControlTemplate.Triggers>
<!-- problem here! -->
<Trigger Property=\"IsPressed\" Value=\"True\">
<Trigger.Setters>
<Setter TargetName=\"ImgBtnScale\" Property=\"ScaleX\" Value=\"0.9\"/>
<Setter TargetName=\"ImgBtnScale\" Property=\"ScaleY\" Value=\"0.9\"/>
</Trigger.Setters>
</Trigger>
<!-- rest of the stuff works okay-->
<Trigger Property=\"IsMouseOver\" Value=\"True\">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName=\"ImgBtnScale\" Storyboard.TargetProperty=\"ScaleX\"
To=\"1.2\" Duration=\"0:0:0.1\"/>
<DoubleAnimation Storyboard.TargetName=\"ImgBtnScale\" Storyboard.TargetProperty=\"ScaleY\"
To=\"1.2\" Duration=\"0:0:0.1\"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName=\"ImgBtnScale\" Storyboard.TargetProperty=\"ScaleX\"
To=\"1\" Duration=\"0:0:0.1\"/>
<DoubleAnimation Storyboard.TargetName=\"ImgBtnScale\" Storyboard.TargetProperty=\"ScaleY\"
To=\"1\" Duration=\"0:0:0.1\"/>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
它不编译,说:
Cannot find the target \'ImgBtnScale\'. (The target must appear before any Setters, Triggers or Conditions that use it.)
那么我如何访问ImgBtnScale
?
没有找到相关结果
已邀请:
2 个回复
缝皋
不是视觉树中的元素,它只是元素属性的值(
)。 相反,您可以做的是通过定义转换的父元素访问转换的属性。例如:
系漏