Jobs Navid

Jobs Navid

  • NA
  • 1
  • 1.9k

Windows Phone 8 ListBox With CheckBox

Apr 25 2014 8:33 AM
I have a listbox:
<ListBox Grid.Row="0" ItemsSource="{Binding ShoppingItems,Mode=TwoWay}" SelectedItem="{Binding SelectedItem,Mode=TwoWay}" FontSize="42" FontWeight="Light" FontFamily="Segoe WP Light" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Visible">


<i:Interaction.Triggers>


<i:EventTrigger EventName="SelectionChanged">


<i:InvokeCommandAction Command="{Binding Tapped}" CommandParameter="{Binding ElementName=List,Path=SelectedItem}"/>


</i:EventTrigger>


</i:Interaction.Triggers>


<ListBox.ItemTemplate>


<DataTemplate>


<Grid>


<Grid.ColumnDefinitions>


<ColumnDefinition Width="Auto"/>


<ColumnDefinition Width="*"/>


</Grid.ColumnDefinitions>


<Grid Grid.Column="0" Margin="0,-19,0,22">


<CheckBox Grid.Column="0" IsChecked="{Binding Path=IsChecked,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" />


</Grid>


<Grid x:Name="MyGrid" Margin="0,-19,0,22" Grid.Column="1">


<Grid.ColumnDefinitions>


<ColumnDefinition Width="Auto"/>


<ColumnDefinition Width="Auto"/>


<ColumnDefinition Width="Auto"/>


</Grid.ColumnDefinitions>


<Grid.RowDefinitions>


<RowDefinition Height="Auto"/>


<RowDefinition Height="Auto"/>


<RowDefinition Height="Auto"/>


</Grid.RowDefinitions>


<TextBlock Text="{Binding DisplayingItem,Mode=TwoWay}" FontSize="46" Grid.Column="0" Grid.Row="0" TextWrapping="Wrap" />


<TextBlock Text="quantity" FontSize="32" Grid.Row="1" Margin="6,0,0,0" Grid.Column="0" TextWrapping="Wrap"/>


<TextBlock Text="{Binding DisplayingQuantity,Mode=TwoWay}" FontSize="32" Grid.Column="1" Grid.Row="1" Margin="32,0,12,12" TextWrapping="Wrap"/>


<TextBlock Grid.Column="2" Grid.Row="1" FontSize="32" Margin="32,0,12,12" Text="{Binding DisplayingPackaging,Mode=TwoWay}" TextWrapping="Wrap"/>


<TextBlock Text="price" Margin="6,0,0,0" FontSize="32" Grid.Row="2" Grid.Column="0" TextWrapping="Wrap"/>


<TextBlock Text="$" FontSize="32" Grid.Row="2" Grid.Column="1" Margin="32,0,12,12" TextWrapping="Wrap"/>


<TextBlock Grid.Column="3" FontSize="32" Grid.Row="2" Margin="32,0,12,12" Text="{Binding DisplayingPrice,Mode=TwoWay}" TextWrapping="Wrap"/>


</Grid>


</Grid>


</DataTemplate>


</ListBox.ItemTemplate>


</ListBox>
and it has a check box inside it, the property bound to my listbox is in my ViewModel,
but when I check an item so that I can delete it here is the deleting Code:
private void Delete(object p)
{
using(var db = new SQLite.SQLiteConnection(App.DB_Path))
{
try
{
if (IsChecked == true)
{
var exists = db.Query<ShoppingModel>("SELECT * FROM ShoppingModel").FirstOrDefault();
if (exists != null)
{
db.RunInTransaction(() =>
{
db.Delete(exists);
MessageBox.Show("Deleted!");
});
}
}
else if (IsChecked != true)
{
MessageBox.Show("No items are checked");
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
The message is that no item has been checked so where is my problem.
here is my Checkbox property:
private bool isChecked;
public bool IsChecked
{
get
{
return isChecked;
}
set
{
if (isChecked != value)
{
isChecked = value;
RaisePropertyChanged("IsChecked");
}
}
}
help me.