这是我的代码:
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="Chrome">
<Grid x:Name="Arrow">
<Grid.Background>
<DrawingBrush Viewport="0,0,4,4" Viewbox="0,-0.4,16,16" ViewboxUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing x:Name="ArrowDrawing">
<GeometryDrawing.Geometry>
<PathGeometry>
<PathFigure StartPoint="1,1" IsClosed="True">
<LineSegment Point="2,2.45"/>
<LineSegment Point="3,1"/>
<LineSegment Point="2,1.75"/>
</PathFigure>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Grid.Background>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Brush" TargetName="ArrowDrawing" Value="{StaticResource DisabledForecolor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
因此,当触发器触发时(在编译时),我收到错误:
找不到触发目标“ArrowDrawing”。 (目标必须出现在使用它的任何 Setter、触发器或条件之前。)
如何从触发器中实际访问名为 ArrowDrawing
的 GeometryDrawing
?
最佳答案
实际上有两种方法可以实现这一点,一种是使用绑定(bind):
Storyboard.Target="{Binding ElementName=ContentPopup}"
另一种是使用 XAML 内部引用:
Storyboard.Target="{x:Reference Name=ContentPopup}"
同样的答案是here !
关于wpf - 访问 ControlTemplate 中的内部元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6097214/