Howdy,
I would like to generate in my application several PivotItems in a pivotelement. The generation is proceeding fine, however I don’t know how I can apply a template to those Pivot Elements.
I thought I would need to use:
pivotItem.ContentTemplate = (DataTemplate)Ressources[“KantinenUebersicht”];
But that is only producing an empty page.
My code in the ressource file looks the following:
inserted my whole ressources File
<.ResourceDictionary
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”>
<DataTemplate x:Key="KantinenTemplate">
<StackPanel VerticalAlignment="Top">
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding name}" FontSize="{StaticResource PhoneFontSizeLarge}" Margin="8,0,0,0" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding entfernung}" Margin="24,0,0,0" FontSize="{StaticResource PhoneFontSizeSmall}" VerticalAlignment="Bottom"/>
</StackPanel>
</DataTemplate>
<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="sdfsdf" HorizontalAlignment="Left" Height="40" Margin="8,59,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="196"/>
<TextBlock x:Name="lblGeoefsdfsdffnet" Height="40" Margin="208,59,8,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
</Grid>
</DataTemplate></ResourceDictionary.>
Had to insert . in the first tags…
What you’re trying to do is correct.
In your question you have an extra “S” in “Resources” which could be the issue.
If I take the code from your question, I can add it to the page:
and then use it when creating a new item:
Works on my machine (emulator).
Update:
If you want to add the resource to a separate file you can do so like:
ResourceDictionary.xaml:Then you must reference this external file in the page which wishes to use this file.