Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在gridview中实现adcontrol,使其';我将显示30个项目,然后是广告,然后是30个项目,然后是广告_C#_Gridview_Windows 8_Microsoft Metro - Fatal编程技术网

C# 如何在gridview中实现adcontrol,使其';我将显示30个项目,然后是广告,然后是30个项目,然后是广告

C# 如何在gridview中实现adcontrol,使其';我将显示30个项目,然后是广告,然后是30个项目,然后是广告,c#,gridview,windows-8,microsoft-metro,C#,Gridview,Windows 8,Microsoft Metro,如何将adcontrol添加到我拥有的gridview中。(项目页面模板) 这是我使用的数据模板: <DataTemplate x:Key="Normal"> <Grid HorizontalAlignment="Left" Width="180" Height="180"> <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}

如何将adcontrol添加到我拥有的gridview中。(项目页面模板)

这是我使用的数据模板:

    <DataTemplate x:Key="Normal">
    <Grid HorizontalAlignment="Left" Width="180" Height="180">
        <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
            <Image Source="{Binding Image}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
        </Border>
        <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
            <TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextStyle}"
                       Height="40"
                       Margin="15,0,15,0"
                       TextAlignment="Center" />
            <TextBlock Text="{Binding Subtitle}" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,15,10"
                       TextAlignment="Center" />
        </StackPanel>
    </Grid>
</DataTemplate>
在我的主页XAML代码中,我完成了以下工作:

xmlns:selectornamespace="using:MyDataSelector"
以下是我的页面资源:

<Page.Resources>
    <!-- Collection of items displayed by this page -->
        <CollectionViewSource
        x:Name="itemsViewSource"
        Source="{Binding Items}"/>
    <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
    <x:String x:Key="AppName">Sample App</x:String>

    <selectornamespace:MyDataTemplateSelector x:Key="Selector" AdTemplate="{StaticResource Ad}" NormalTemplate="{StaticResource Normal}"></selectornamespace:MyDataTemplateSelector>
</Page.Resources>
NormalTemplate和AdTemplate位于StandardStyles.xaml中

任何帮助都将不胜感激! 感谢和圣诞快乐

使用,然后在该模式下检测该项目是否只是虚拟“广告”项目,然后显示添加数据模板而不是标准模板

您将需要在数据源中每30个项目之后插入一个虚拟项目,但是要使其起作用,请使用,然后在该过程中检测该项目是否只是一个虚拟“广告”项目,然后显示添加数据模板而不是标准模板


您将需要在数据源中每30个项目之后插入一个虚拟项目,但要使其正常工作

感谢链接,我已经尝试过了!:)现在我有另一个问题,它找不到类。你能帮我吗?谢天谢地,这很容易-让MyDataTemplateSelector公开:-)谢谢你的链接,我试过了!:)现在我有另一个问题,它找不到类。你能帮我吗?谢天谢地,这很容易-将MyDataTemplateSelector公开:-)我可以建议吗:我可以建议:
<Page.Resources>
    <!-- Collection of items displayed by this page -->
        <CollectionViewSource
        x:Name="itemsViewSource"
        Source="{Binding Items}"/>
    <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
    <x:String x:Key="AppName">Sample App</x:String>

    <selectornamespace:MyDataTemplateSelector x:Key="Selector" AdTemplate="{StaticResource Ad}" NormalTemplate="{StaticResource Normal}"></selectornamespace:MyDataTemplateSelector>
</Page.Resources>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace MyDataSelector
{
    private class MyDataTemplateSelector : DataTemplateSelector
    {
        public DataTemplate NormalTemplate { get; set; }
        public DataTemplate AdTemplate{ get; set; }
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            if (item is TestApp.Mainpage.NormalData)
                return NormalTemplate
            if (item is TestApp.Mainpage.AdData)
                return AdTemplate;

            return SelectTemplateCore(item, container);
        }
    }
}