public class Customer
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string Contact { get; set; }
public ObservableCollection<Customer> _customerlist { get; set; }
public Customer CustomerToAdd { get; set; }
public RelayCommand AddCustomerCommand { get; set; }
private async void addCustomer()
{
var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path,"data.db3");
using (var db = new SQLite.SQLiteConnection(dbpath))
{
db.Insert(new Customer()
{
Name = CustomerToAdd.Name,
Contact = CustomerToAdd.Contact,
City = CustomerToAdd.City,
});
db.Commit();
db.Dispose();
db.Close();
var line = new MessageDialog("Records Inserted");
await line.ShowAsync();
}
}
public RelayCommand DeleteSelectedCustomerCommand { get; set; }
private void deleteSelectedCustomer()
{
}
public RelayCommand EditSelectedCustomerCommand { get; set; }
private void editSelectedCustomer()
{
}
public RelayCommand DeleteAllCustomerCommand { get; set; }
private void deleteAll()
{
}
public MainPageViewModel()
{
AddCustomerCommand = new RelayCommand(addCustomer);
CustomerToAdd = new Customer();
_customerlist = new ObservableCollection<Customer>();
DeleteAllCustomerCommand = new RelayCommand(deleteAll);
EditSelectedCustomerCommand = new RelayCommand(editSelectedCustomer);
DeleteSelectedCustomerCommand = new RelayCommand(deleteSelectedCustomer);
}
<Page.DataContext>
<ViewModels:MainPageViewModel>
</ViewModels:MainPageViewModel>
</Page.DataContext>
<Grid removed="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView ItemsSource="{Binding _customerlist}"
HorizontalAlignment="Left" Margin="44,65,0,327" Width="456">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Width="400" removed="Chocolate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontSize="30" />
<TextBlock Text="," FontSize="30" />
<TextBlock Text="{Binding City }" FontSize="30" />
</StackPanel>
<TextBlock Text="{Binding Contact}" FontSize="30" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Command="{Binding AddCustomerCommand}"
Content="Add person"
FontSize="40" Margin="588,465,0,230"/>
<Button Command="{Binding EditSelectedCustomerCommand}"
Content="Edit"
FontSize="40" Margin="865,465,0,230"/>
<Button Command="{Binding DeleteSelectedCustomerCommand}"
Content="Delete"
FontSize="40" Margin="1037,465,0,230" />
<Button Command="{Binding DeleteAllCustomerCommand }"
Content="Delete All"
FontSize="40" Margin="979,619,0,76" />
<TextBlock Text="Name" FontSize="30" Margin="633,65,598,640" Height="63"/>
<TextBox DataContext="{Binding CustomerToAdd}" Text="{Binding Name, Mode=TwoWay}"
FontSize="30" Margin="868,62,80,640"/>
<TextBlock Text="City " FontSize="30" Margin="633,181,551,524"/>
<TextBox DataContext="{Binding CustomerToAdd}" Text="{Binding City, Mode=TwoWay}"
FontSize="30" Margin="868,181,80,525"/>
<TextBlock Text="Contact" FontSize="30" Margin="633,296,536,400"/>
<TextBox DataContext="{Binding CustomerToAdd}" Text="{Binding Contact, Mode=TwoWay}"
FontSize="30" Margin="868,296,80,403"/>
</Grid>
i am insert data and its show "Records Inserted" but list box not showing that data