我有这个翻转视图:
<FlipView x:Name="models_list" SelectionChanged="selectionChanged">
<FlipView.ItemTemplate>
<DataTemplate>
<Grid x:Name="cv">
<Image x:Name="img1" Source = "{Binding ModelImage}" Stretch="Fill" Tag="{Binding ModelTag}"/>
</Grid>
</DataTemplate>
</FlipView.ItemTemplate>
我想找到当前选定索引的img1。在搜索它时,我在这里的一些帖子中找到了此方法:
private DependencyObject FindChildControl<T>(DependencyObject control, string ctrlName)
{
int childNumber = VisualTreeHelper.GetChildrenCount(control);
for (int i = 0; i < childNumber; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(control, i);
FrameworkElement fe = child as FrameworkElement;
// Not a framework element or is null
if (fe == null) return null;
if (child is T && fe.Name== ctrlName)
{
// Found the control so return
return child;
}
else
{
// Not found it - search children
DependencyObject nextLevel = FindChildControl<T>(child, ctrlName);
if (nextLevel != null)
return nextLevel;
}
}
return null;
}
它向我返回了flipview的第一个索引上的Image,但我需要当前选择的索引上存在的图像。我尝试编辑此方法,但找不到所需的控件。谁能帮我?
月关宝盒