DataTamplate IN XAML Xamarin - PullRequest
       0

DataTamplate IN XAML Xamarin

0 голосов
/ 30 ноября 2018

Мне нужно добавить ссылку на ItemTemplate, как показано ниже:

            <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr- 
              namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="InfoSeries.Views.MainPage"
             Title="Info Series">

  <ContentPage.Resources>
    <ResourceDictionary>
      <DataTemplate x:Key="TopSeriesTemplate">
        <ViewCell>
          <ViewCell.View>
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="2*" />
                </Grid.ColumnDefinitions>
                <StackLayout>
                    <Label Text="{Binding Network}" FontSize="14" TextColor="#98a6ad" Margin="5, 0, 0, 0" />                    
                </StackLayout>
            </Grid>
          </ViewCell.View>
        </ViewCell>   
       </DataTemplate>
    </ResourceDictionary>
  </ContentPage.Resources>

  <ListView ItemTemplate="{StaticResource TopSeriesTemplate}"
            ItemsSource="{Binding Path=TopSeries}"/>

Я пробовал много, если разные вещи, но приведенный ниже код настолько же близок, насколько я дошел.

 <ListView ItemTemplate="{StaticResource TopSeriesTemplate}"
        ItemsSource="{Binding Path=TopSeries}"  >
              <behaviors:Interaction.Behaviors>
                <behaviors:BehaviorCollection>
                  <behaviors:EventToCommand EventName="ItemTapped" 
                      Command="{Binding GoToDetailPage}" />
                    </behaviors:BehaviorCollection>
                    </behaviors:Interaction.Behaviors>
               <ListView.ItemTemplate>
                <DataTemplate x:key="TopSeriesTemplate">
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout VerticalOptions="Center" Margin="30,0,0,0" Orientation="Horizontal">

                               <Label Text="{Binding name}" TextColor="Black" FontSize="20" VerticalOptions="Center">


                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

В этом заключается ошибка: StaticResource не найден для ключа TopSeriesTemplate

Я также добавил Xam.Behaviors (Nuget) и добавил следующее:

xmlns:behaviors="clr-namespace:Xam.Behaviors;assembly=Xam.Behaviors"

Я следовал этому руководству: https://blog.qmatteoq.com/prism-for-xamarin-forms-basic-navigation-and-dependency-injection-part-2/#comment-51794

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...