【发布时间】:2018-07-12 09:57:07
【问题描述】:
我有一个简单的动态 Gridview:
<GridView x:Name="MainGridStations" ItemsSource="{x:Bind Stations}" IsItemClickEnabled="True" ItemClick="GridView_ItemClick">
<GridView.ItemTemplate>
<DataTemplate x:DataType="local:Station">
<Grid>
<Grid Background="White" HorizontalAlignment="Center" Width="300" Height="200" VerticalAlignment="Center">
<Image x:Name="ImageStation" Source="{Binding ImageURL}"/>
<Grid Background="#e4f0fc" Height="65" VerticalAlignment="Bottom" Opacity="0.8">
<TextBlock x:Name="StationName" Text="{Binding Name}" FontWeight="Bold" Foreground="#2c9a8b" HorizontalAlignment="Center" />
</Grid>
</Grid>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
现在我想在这个 gridview 中使用原生广告。在本机广告的代码中,我需要注册包含点击事件等广告的广告容器。 它始终是 gridview 的第一个子项,即 gridview 中的第一个网格容器。
我试过这个:
nativeAd.RegisterAdContainer(MainGridStations.ContainerFromIndex(0));
这里给了我一个错误,它不能从 Windows.UI.Xaml.DependencyObject 转换为 Windows.UI.Xaml.FrameworkElement
基本上它需要一个我无法提供的 xaml 控件的直接名称。 我该如何克服呢?
【问题讨论】:
标签: c# xaml gridview datagridview uwp