0
首先,我嘗試了其他一些在stackoverflow上回答的示例,並嘗試了其他示例,但沒有在我的案例中找到成功。將數據從SQLite綁定到Windows Phone 8.1中的ListView
我試圖從數據庫表中數據綁定到ListView的 ListView控件本身看起來是這樣的:
<ListView x:Name="lbItems" Width="Auto" Height="Auto" Margin="10" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Opacity="100" BorderThickness="0" Foreground="White" Background="Transparent">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="60" />
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" x:Name="cbx" IsChecked="{Binding IsChecked}" Content="{Binding Content}" Height="58" Margin="10, 0, 0, 0" HorizontalAlignment="Stretch" VerticalAlignment="Center" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" Width="Auto" />
<AppBarButton Tag="{Binding Id}" Grid.Column="1" Icon="Delete" Height="58" HorizontalAlignment="Right" Width="60" VerticalAlignment="Stretch" HorizontalContentAlignment="Right" Margin="0,0,10,0" Click="DeleteButton_Click" />
</Grid>
</ListView>
,然後在後面的C#代碼:
public sealed partial class MainPage : Page
{
ObservableCollection<tbl_Items> DB_ItemsList = new ObservableCollection<tbl_Items>();
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ReadAllItemsList dbitems = new ReadAllItemsList();
DB_ItemsList = dbitems.GetAllItems();
lbItems.ItemsSource = DB_ItemsList.OrderBy(i => i.Id).ToList();
}
在這裏,我以下這個例子用於創建數據庫和數據庫操作:LINK
因此,在我的listview中,我只能得到我的表名(instea d綁定來自該表的內容)。 我無法弄清楚我做錯了什麼。請幫助。
謝謝老兄,你是救命恩人。我已經花了大約一週的時間,找不到任何解釋如何去做。 – al1en