I'm trying to bind my data from sqlite.net database into textblock. I've searched a lot about it, but I still have a few problems: 1) anoying exception occurs where in the Additional Information is: "Constraint" and nothing else. The problem is also that it doesn't appear every time I run the app. 2) I cannot see my Binding data into the textblock.
I've composed me code according to this example: Windows Store App writing sqlite query into the listview's textblocks
I've tried also this select data from sqlite database and binding values to listbox item in windows phone 8 apps but none of this solving my problem.
Here is my XAML code:
<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();
}
}
Hope to hear from you some piece of advice. Best regards, Tomas
Aucun commentaire:
Enregistrer un commentaire