我正在尝试获取ElementHost控件的引用。例如,在下面的代码中,我需要最初使用WPF用户控件的“testImage”内容来启动事件。WPF控件是在运行时添加的,因此ElementHost控件也是如此,因此我无法使用WPF控件的名称或ElementHost的名称。
我的逻辑是获取“testImage”的父WPF用户控件,然后获取WPF用户控件的父ElementHost。
但我在编写代码时遇到了麻烦。请给予建议。谢谢。
<UserControl x:Class="WpfTest”
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="300" Height="300">
<Grid>
<Label FontSize="10" Height="24" Margin="74,16,0,0" Name="testLabel" VerticalAlignment="Top" />
<Image Name="testImage" Stretch="Uniform" HorizontalAlignment="Left" Width="64" Height="81" VerticalAlignment="Top" Margin="8,0,0,0"/>
</Grid>
</UserControl>