我试图将我的数据从sqlite.net数据库绑定到textblock。我已经搜索了很多关于它的信息,但我还是有一些问题: 1)发生了令人讨厌的异常,其中附加信息是:"约束"没有别的。问题还在于每次运行应用程序时都不会出现。 2)我无法在文本块中看到我的Binding数据。
我根据这个例子编写了代码:Windows Store App writing sqlite query into the listview's textblocks
我也试过这个select data from sqlite database and binding values to listbox item in windows phone 8 apps 但这些都没有解决我的问题。
这是我的XAML代码:
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/Assets/rankingTlo.png"/>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="Pytanie" VerticalAlignment="Top" FontFamily="Arial" FontSize="20" Margin="-83,71,0,0" Foreground="#FF353535" FontWeight="Bold"/>
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="2" VerticalAlignment="Top" Foreground="#FFB41019" Margin="17,59,0,0" FontFamily="Arial" FontWeight="Bold" FontSize="33" />
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="z" VerticalAlignment="Top" Foreground="#FF353535" Margin="56,71,0,0" FontFamily="Arial" FontWeight="Bold" FontSize="20" />
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="14" VerticalAlignment="Top" Foreground="#FF353535" Margin="109,59,0,0" FontFamily="Arial" FontWeight="Bold" FontSize="33" />
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="poziom" VerticalAlignment="Top" FontFamily="Arial" FontSize="16" Margin="-88,96,0,0" Foreground="#FF353535" FontWeight="Bold"/>
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Text="licealista" VerticalAlignment="Top" FontFamily="Arial" FontSize="16" Margin="47,96,0,0" Foreground="#FFB41019" FontWeight="Bold"/>
<ListView Name="listView1" Grid.Column="1" Grid.Row="1" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Width="Auto" Height="50" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding tresc_pytania}" VerticalAlignment="Top" Foreground="Black" FontFamily="Arial" FontSize="24"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
class pytania
{
[PrimaryKey]
public int id_pytania { get; set; }
public string tresc_pytania { get; set; }
public int poziom_trudnosci { get; set; }
public string odpowiedz1 { get; set; }
public string odpowiedz2 { get; set; }
public string odpowiedz3 { get; set; }
public string odpowiedz4 { get; set; }
public int dobra_odpowiedz { get; set; }
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "baza.ext");
using (var dbConn = new SQLite.SQLiteConnection(dbPath))
{
var query = dbConn.Table<pytania>();
listView1.ItemsSource = query.ToList();
}
}
希望收到一些建议。 最好的祝福, 托马斯