2017-06-16 4 views
0

私はXamarinを学び始めました。最初のテストプロジェクトを作成しようとしています。 BindingContextからObservableCollectionを表示するListViewを作成しました。 "Take"は3つのプロパティを持つテーブルです。問題は、エミュレータでアプリケーションを実行すると、次のエラーダイアログが表示されます。「プロセスシステムが応答していません。終了しますか?」
しかし、私はタグとすべての内部XAMLコードをすべて消去するが、私はListViewの各要素でクラス "テイク"のプロパティの値をdispalayしたい。XamarのXAMLリストビューが機能しません

<?xml version="1.0" encoding="utf-8" ?> 

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="App1.Views.Page1"> 

<ContentPage.Content> 
    <StackLayout> 
     <Label Text="Welcome to my first project"></Label> 
     <Label Text="Why does it does not work?"></Label> 
     <ListView ItemsSource="{Binding GetList}"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
        <TextCell Text="{Binding Word}"></TextCell> 
        <Button Text="SomeText"></Button> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
     </ListView> 
    </StackLayout> 
</ContentPage.Content> 
</ContentPage> 

そして、これが私のC#BindingContextを

public class SQLiteSamplePage 
{ 
    private readonly SQLiteConnection _sqLiteConnection; 
    private ObservableCollection<Take> list; 

    public SQLiteSamplePage() 
    { 
     _sqLiteConnection = DependencyService.Get<ISQLite>().GetConnection(); 
     _sqLiteConnection.CreateTable<Take>(); 
     _sqLiteConnection.Insert(new Take 
     { 
      Word = "SomeWord1", 
      Translation = "Some translation 1" 
     }); 

     _sqLiteConnection.Insert(new Take 
     { 
      Word = "SomeWord", 
      Translation = "SomeTranslation" 
     }); 

     list =new ObservableCollection<Take>(_sqLiteConnection.Table<Take>()); 
    } 
    public ObservableCollection<Take> GetList 
    { 
     get { return list; } 
    } 
} 

そして、ここでは、テーブルのコード

public class Table 
{ 
    [PrimaryKey, AutoIncrement] 
    public int ID { get; set; } 
    public string Word { get; set; } 
    public string Translation { get; set; } 
} 
+0

DataTemplateからButtonを削除してみます – Jason

答えて

0

TextCellStackLayoutかのいずれかの種類でButtonを配置しようとするとされています内部のレイアウト<ViewCell>要素:

<ListView ItemsSource="{Binding GetList}"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <ViewCell> 
       <StackLayout> 
        <TextCell Text="{Binding Word}"></TextCell> 
        <Button Text="SomeText"></Button> 
       </StackLayout> 
      </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

DataTemplate要素の子は、タイプViewCellであるか、派生している必要があります。

0

TextCellと他のもの(あなたの場合はButton)を組み合わせることはできません。テキストとボタンの両方を表示するには、カスタムセルを使用する必要があります。

この

は、基本クラス ViewCellを使用して行われ、内部が、あなたはこのことができます

<StackLayout> 
    <Label Text="Welcome to my first project"></Label> 
    <Label Text="Why does it does not work?"></Label> 
    <ListView ItemsSource="{Binding GetList}"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell> 
        <StackLayout> 
         <Label Text="{Binding Word}"></Label> 
         <Button Text="SomeText"></Button> 
        </StackLayout> 
       </ViewCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 
</StackLayout> 

希望を表示するレイアウトを定義します。

関連する問題