2016-09-14 8 views
2

Xamarin.Formsデータベース項目を表示するためのページがあります。 StringとしてGuidとしてIdを、MandantId Guidとして、DateTimeとしてUpdateAtとURL:XAMLラベルへのバインド

public ListItemsPage() 
{ 
    DatabaseHelper tmpDBHelper = new DatabaseHelper(); 
    InitializeComponent(); 

    listView.ItemsSource = tmpDBHelper.GetItems(); 
} 

これらのアイテムは、4列を持っています。

私はXAMLでこれをこのようにバインドしたいと思います。

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="Portable.Pages.ListItemsPage" 
      Title="DbItemExample"> 
    <ListView x:Name="listView"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
     <ViewCell> 
      <ViewCell.View> 
      <StackLayout Padding="20,0,20,0" 
         Orientation="Horizontal" 
         HorizontalOptions="FillAndExpand"> 

       <Label Text="{Binding Id}" 
        HorizontalOptions="StartAndExpand" /> 
       <Label Text="{Binding Url}" 
            HorizontalOptions="StartAndExpand" /> 
       <Label Text="{Binding MandantId}" 
            HorizontalOptions="StartAndExpand" /> 
       <Label Text="{Binding UpdateAt}" 
            HorizontalOptions="StartAndExpand" /> 
      </StackLayout> 
      </ViewCell.View> 
     </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
    </ListView> 
</ContentPage> 

これが役立つ場合は、ここに私のモデルであるdbテーブルが生成されています。

class DbItem 
{ 
    [PrimaryKey] 
    public Guid Id { get; set; } 
    public Guid MandantId { get; set; } 
    public string Url { get; set; } 
    public DateTime UpdateAt { get; set; } 
} 

URLとUpdateAtのみが表示されます。何故ですか?

+0

'Url'と' MandantId'はデータベースから来ていますか? –

+0

@EgorGromadskiyはいそうです。私はすべてのプロパティを持つcsファイルの項目を取得します。 – greenhoorn

+0

私は 'EmptyConverter'を追加し、バインディングが動作するかどうかを確認します。 –

答えて

1

私はそれを修正しました。

Egor Gromadskiyから提案されたように、私はEmptyConverter(Binding errors in Xamarin Forms)を実装しました。 XamarinはGuidを文字列に自動的に変換できないようです。

Convert()valuevalue.ToString()に変更するだけです。

+0

_ItはId_のみを表示しますが、 'Id'は' Guid'です。だからなぜ 'Id'が出てくるのだろう? –

+0

@EgorGromadskiy申し訳ありませんが、それはURLとUpdateAtを表示しています。それは、DateTimeではToString()を呼び出していますが、Guidでは呼び出されていません。 – greenhoorn

関連する問題