locked
[UWP][XAML] - The resource "(...)" could not be resolved. - Error on ItemTemplate in a DataTemplate RRS feed

  • Question

  • Hi!

    I got a listview which has an ItemTemplate bound to a DataTemplate up in my UserControl.Resources. In that DataTemplate, there's another ListView with it's own ItemTemplate bound to another DataTemplate in the Resources section. However, I get an error (still deployable):

    The resource "gridViewTemplate" could not be resolved.	
    


    Below is a raw output of my UserControl.Resources..

        <UserControl.Resources>
            <DataTemplate x:Name="TripListTemplate">
                <Grid VerticalAlignment="Top" Padding="10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition />
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition  Height="Auto"/>
                        <RowDefinition  Height="Auto"/>
                        <RowDefinition  Height="Auto"/>
                    </Grid.RowDefinitions>
    
                    <TextBlock Text="{Binding edep}"/>
                    <TextBlock Text="{Binding adep}" Grid.Row="1" Foreground="#FF5500"/>
                    <TextBlock Text="{Binding earr}" Grid.Column="2"/>
                    <TextBlock Text="{Binding aarr}" Grid.Row="1" Grid.Column="2" Foreground="#FF5500"/>
                    <Grid Grid.Column="1" Grid.RowSpan="2" Margin="0" Width="Auto" Padding="5,0">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
    
                        <ListView ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Auto"
        ScrollViewer.HorizontalScrollMode="Enabled"                  
        ScrollViewer.VerticalScrollMode="Disabled"
        ItemsSource="{Binding exchangeView}" ItemTemplate="{StaticResource gridViewTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" SelectionMode="None" IsHitTestVisible="False">
                            <ListView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Background="Transparent" Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ListView.ItemsPanel>
                            <ListView.ItemContainerStyle>
                                <Style TargetType="ListViewItem">
                                    <Setter Property="Padding" Value="4,0,4,0"/>
                                    <Setter Property="MinWidth" Value="0"/>
                                </Style>
                            </ListView.ItemContainerStyle>
                        </ListView>
                    </Grid>
                    <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" >
                        <TextBlock Text="Restid: "/>
                        <TextBlock Text="{Binding totaltime}"/>
                        <TextBlock Text=" Byten: "/>
                        <TextBlock Text="{Binding exchanges}"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
    
            <DataTemplate x:Key="gridViewTemplate">
                <Grid Background="{Binding background}" Padding="10,5" Width="auto">
                    <TextBlock Text="{Binding name}" Foreground="{Binding foreground}"/>
                </Grid>
            </DataTemplate>
        </UserControl.Resources>
    

    Should I go on another way to do this, or?

    Any help would be appreciated!

    Thanks!

    Wednesday, August 3, 2016 8:53 PM

Answers

  • Define the "gridViewTemplate" DataTemplate before the ListView or wherever it is used:

    <UserControl.Resources>
            <DataTemplate x:Key="gridViewTemplate">
                <Grid Background="{Binding background}" Padding="10,5" Width="auto">
                    <TextBlock Text="{Binding name}" Foreground="{Binding foreground}"/>
                </Grid>
            </DataTemplate>
    
            <DataTemplate x:Name="TripListTemplate">
                <Grid VerticalAlignment="Top" Padding="10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition />
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition  Height="Auto"/>
                        <RowDefinition  Height="Auto"/>
                        <RowDefinition  Height="Auto"/>
                    </Grid.RowDefinitions>
    
                    <TextBlock Text="{Binding edep}"/>
                    <TextBlock Text="{Binding adep}" Grid.Row="1" Foreground="#FF5500"/>
                    <TextBlock Text="{Binding earr}" Grid.Column="2"/>
                    <TextBlock Text="{Binding aarr}" Grid.Row="1" Grid.Column="2" Foreground="#FF5500"/>
                    <Grid Grid.Column="1" Grid.RowSpan="2" Margin="0" Width="Auto" Padding="5,0">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
    
                        <ListView ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Auto"
        ScrollViewer.HorizontalScrollMode="Enabled"                  
        ScrollViewer.VerticalScrollMode="Disabled"
        ItemsSource="{Binding exchangeView}" ItemTemplate="{StaticResource gridViewTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" SelectionMode="None" IsHitTestVisible="False">
                            <ListView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Background="Transparent" Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ListView.ItemsPanel>
                            <ListView.ItemContainerStyle>
                                <Style TargetType="ListViewItem">
                                    <Setter Property="Padding" Value="4,0,4,0"/>
                                    <Setter Property="MinWidth" Value="0"/>
                                </Style>
                            </ListView.ItemContainerStyle>
                        </ListView>
                    </Grid>
                    <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" >
                        <TextBlock Text="Restid: "/>
                        <TextBlock Text="{Binding totaltime}"/>
                        <TextBlock Text=" Byten: "/>
                        <TextBlock Text="{Binding exchanges}"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
    
        </UserControl.Resources>
    

    The order of resources matters.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by Vincent Gio Wednesday, August 3, 2016 9:25 PM
    Wednesday, August 3, 2016 9:04 PM

All replies

  • Define the "gridViewTemplate" DataTemplate before the ListView or wherever it is used:

    <UserControl.Resources>
            <DataTemplate x:Key="gridViewTemplate">
                <Grid Background="{Binding background}" Padding="10,5" Width="auto">
                    <TextBlock Text="{Binding name}" Foreground="{Binding foreground}"/>
                </Grid>
            </DataTemplate>
    
            <DataTemplate x:Name="TripListTemplate">
                <Grid VerticalAlignment="Top" Padding="10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition />
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition  Height="Auto"/>
                        <RowDefinition  Height="Auto"/>
                        <RowDefinition  Height="Auto"/>
                    </Grid.RowDefinitions>
    
                    <TextBlock Text="{Binding edep}"/>
                    <TextBlock Text="{Binding adep}" Grid.Row="1" Foreground="#FF5500"/>
                    <TextBlock Text="{Binding earr}" Grid.Column="2"/>
                    <TextBlock Text="{Binding aarr}" Grid.Row="1" Grid.Column="2" Foreground="#FF5500"/>
                    <Grid Grid.Column="1" Grid.RowSpan="2" Margin="0" Width="Auto" Padding="5,0">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
    
                        <ListView ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Auto"
        ScrollViewer.HorizontalScrollMode="Enabled"                  
        ScrollViewer.VerticalScrollMode="Disabled"
        ItemsSource="{Binding exchangeView}" ItemTemplate="{StaticResource gridViewTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" SelectionMode="None" IsHitTestVisible="False">
                            <ListView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Background="Transparent" Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ListView.ItemsPanel>
                            <ListView.ItemContainerStyle>
                                <Style TargetType="ListViewItem">
                                    <Setter Property="Padding" Value="4,0,4,0"/>
                                    <Setter Property="MinWidth" Value="0"/>
                                </Style>
                            </ListView.ItemContainerStyle>
                        </ListView>
                    </Grid>
                    <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" >
                        <TextBlock Text="Restid: "/>
                        <TextBlock Text="{Binding totaltime}"/>
                        <TextBlock Text=" Byten: "/>
                        <TextBlock Text="{Binding exchanges}"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
    
        </UserControl.Resources>
    

    The order of resources matters.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Marked as answer by Vincent Gio Wednesday, August 3, 2016 9:25 PM
    Wednesday, August 3, 2016 9:04 PM
  • Welp, that does really make sense!

    Thank you for this quick answer, was getting annoyed with the error message!


    Wednesday, August 3, 2016 9:25 PM