2016-07-20 9 views
-1

フォーム私はListViewコントロールから選択したときにfirtページからSqlit 以下に、コードからListViewのページ[リストビュー戻るデータから移動しよう: XAMLコード:オブジェクトが一致しない、Xamarinは

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="FirstTestApp.AllTripsPage" 
     Title="AllTrips"> 
<ContentPage.Content> 
    <StackLayout Orientation="Vertical"> 

     <ListView x:Name="TripsList" ItemSelected="TripsList_ItemSelected"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell> 
        <StackLayout Orientation="Horizontal" Padding="5,5,5,5"> 
         <Label Text="{Binding Name}" FontSize="Medium" /> 
         </StackLayout> 
       </ViewCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 
    </StackLayout> 
</ContentPage.Content> 

C#の機能:

private async void TripsList_ItemSelected(object sender, SelectedItemChangedEventArgs e) 
    { 
     if (e.SelectedItem == null) 
     { 
      return; 
      //ItemSelected is called on deselection, 
      //which results in SelectedItem being set to null 
     } 
     var Selected = (Trip)e.SelectedItem; 

     await Navigation.PushAsync(new ShowTrip(Selected)); 

    } 

このコードページShowTripで、それは私が町項目に関するいくつかの詳細を表示氷: XAMLコード:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="FirstTestApp.ShowTrip" 
     Title="Trip Details"> 
<ContentView.Content> 
    <Label Text="Trip Details" /> 
     <Label Text="Name" /> 
     <Label Text ="{Binding Name}" /> 
     <Label Text="Description" /> 
     <Label Text ="{Binding Description}"/> 
     <Label Text="Done:" /> 
    <Label Text ="{Binding Done}"/> 
</ContentView.Content> 

のC#:

public partial class ShowTrip : ContentPage 
{ 
    Trip SelectTrip; 
    public ShowTrip(Trip Selected) 
    { 

     InitializeComponent(); 
     SelectTrip = Selected; 
     BindingContext = SelectTrip; 
    } 

} 

エラー(のInitializeComponentに表示されます)機能:

private void InitializeComponent() { 
     this.LoadFromXaml(typeof(ShowTrip));///in This Line Exception happened 
    } 

エラーがある:「オブジェクトはありませんターゲットタイプに一致しません "

+0

XAMLでエラーが発生しました.XAMLコードを投稿してください。 –

+0

@EgorGromadskiy私は編集しました –

+0

'ShowTrip'ページで' 'の代わりに' StackLayout'を使うようにしてください。 –

答えて

1

の代わりにStackLayoutShowTripページに表示してみてください。

関連する問題