我的xml:
<Style x:Key="grid_image_panel" TargetType="ContentControl">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid x:Name="image_panel">
<Image Name="img" Source="Resources/rhcp.jpg" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
我需要在我的 C# 代码隐藏中为图像“img”设置事件“Tap”:
DataTemplate dt = gridy.ContentTemplate as DataTemplate;
DataTemplate dt = gridy.ContentTemplate as DataTemplate;
Grid grid = dt.LoadContent() as Grid;
Image img = grid.Children.First() as Image;
img.Tap += OnTapped;
结果:点击无效