Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
private bool isChecked;
public bool IsChecked
 {
get
 {
return isChecked;
 }
set
 {
if (isChecked != value)
 {
 isChecked = value;
 RaisePropertyChanged("IsChecked");
 }
 }
 }


help me.
Posted
Updated 25-Apr-14 7:37am
v16
Comments
BELGIUMsky 25-Apr-14 10:57am    
can you debug your code?

set an debug break at your setter of your ischecked method;
and run your program as debug

if you see that a value is changed then the problem is not your ischecked binding
Jobs Mwaniki Navid 25-Apr-14 12:49pm    
1.I forgot to tell you, my props are in a class that my ViewModel inherits from.
the IsChecked is not in my ViewModel, could that be a problem.
2.do you mean I should set my breakpoint in my Delete Method or in my IsChecked Prop?
BELGIUMsky 27-Apr-14 6:06am    
i mean in your ischecked property

set
{
if (isChecked != value) // on this line
{
isChecked = value;
RaisePropertyChanged("IsChecked");
}
}
}
Sunasara Imdadhusen 26-Apr-14 5:27am    
Please do not post entire code over here!!
Jobs Mwaniki Navid 26-Apr-14 8:17am    
I did it for clarification, plus its not my entire code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900