代码之家  ›  专栏  ›  技术社区  ›  KalleP

XAML-Xamarin中的DataTamplate

  •  0
  • KalleP  · 技术社区  · 6 年前

                <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>
    

    我还补充道Xam.行为(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

    0 回复  |  直到 6 年前