Windows phone 7 如何使用数据[模板]填充生成的透视元素

Windows phone 7 如何使用数据[模板]填充生成的透视元素,windows-phone-7,Windows Phone 7,你好, 我想在我的应用程序中在一个数据透视元素中生成几个数据透视项。生成过程进行得很顺利,但是我不知道如何将模板应用于这些枢轴元素 我想我需要使用: pivotItem.ContentTemplate=(DataTemplate)资源[“KantinenUebersicht”] 但这只会产生一个空白页 我在ressource文件中的代码如下所示: 插入了我的整个资源文件 必须插入。在第一个标签中…您试图做的是正确的 在您的问题中,您在“资源”中有一个额外的“S”,这可能是问题所在 如果我

你好, 我想在我的应用程序中在一个数据透视元素中生成几个数据透视项。生成过程进行得很顺利,但是我不知道如何将模板应用于这些枢轴元素

我想我需要使用:

pivotItem.ContentTemplate=(DataTemplate)资源[“KantinenUebersicht”]

但这只会产生一个空白页

我在ressource文件中的代码如下所示:

插入了我的整个资源文件



必须插入。在第一个标签中…

您试图做的是正确的

在您的问题中,您在“资源”中有一个额外的“S”,这可能是问题所在

如果我从您的问题中提取代码,我可以将其添加到页面:

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Key="KantinenUebersicht">
        <Grid>
            <TextBlock x:Name="KantinenName" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Text="" RenderTransformOrigin="0.566,0.407" Margin="0,0,8,0" Height="55" VerticalAlignment="Top">
                 <TextBlock.Foreground>
                  <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                 </TextBlock.Foreground>
            </TextBlock>
            <TextBlock x:Name="lblEntfernung" HorizontalAlignment="Left" Height="40" Margin="8,59,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="196"/>
            <TextBlock x:Name="lblGeoeffnet" Height="40" Margin="208,59,8,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
        </Grid>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>
在我的机器上工作(仿真器)

更新:
如果要将资源添加到单独的文件中,可以执行以下操作:

ResourceDictionary.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <DataTemplate x:Key="KantinenUebersicht">
        <Grid>
            <TextBlock x:Name="KantinenName" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Text="" RenderTransformOrigin="0.566,0.407" Margin="0,0,8,0" Height="55" VerticalAlignment="Top">
                     <TextBlock.Foreground>
                      <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                     </TextBlock.Foreground>
            </TextBlock>
            <TextBlock x:Name="lblEntfernung" HorizontalAlignment="Left" Height="40" Margin="8,59,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="196"/>
            <TextBlock x:Name="lblGeoeffnet" Height="40" Margin="208,59,8,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
        </Grid>
    </DataTemplate>
</ResourceDictionary>

然后,您必须在希望使用此文件的页面中引用此外部文件

<phone:PhoneApplicationPage.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="\ResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</phone:PhoneApplicationPage.Resources>


实际上,Resources中的第二个“s”是在将其键入框中时发生的错误。但是缺少的是“”,但当我将其添加到Resources文件时,它会返回一个error@theXs你的“资源文件”是什么?我上面的代码示例来自MainPage.xaml。到目前为止,我的资源文件名是“ResourceDictionary1.xaml”。我只是试着调试和检查我在“this.resources”下看到的内容。。但它是一个空字典-这可能也意味着为什么我看不到任何输出。@XS更新的答案显示使用单独文件中指定的模板实际上,我觉得有点愚蠢,但我无法在我的XAML文件中实现。它说它不能有两个根元素,但是一旦我尝试将它设置为类似
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <DataTemplate x:Key="KantinenUebersicht">
        <Grid>
            <TextBlock x:Name="KantinenName" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Text="" RenderTransformOrigin="0.566,0.407" Margin="0,0,8,0" Height="55" VerticalAlignment="Top">
                     <TextBlock.Foreground>
                      <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                     </TextBlock.Foreground>
            </TextBlock>
            <TextBlock x:Name="lblEntfernung" HorizontalAlignment="Left" Height="40" Margin="8,59,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="196"/>
            <TextBlock x:Name="lblGeoeffnet" Height="40" Margin="208,59,8,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
        </Grid>
    </DataTemplate>
</ResourceDictionary>
<phone:PhoneApplicationPage.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="\ResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</phone:PhoneApplicationPage.Resources>