My app has a two ListBoxes. I need, when the user hold a item from my ListBox1
, the same item should appear in ListBox2
.
My current code works, but I need select item (touch item) before hold item. I know that reason is i'm using SelectedItem
, but how do for hold event?
My code:
private void holdListAdd(object sender, System.Windows.Input.GestureEventArgs e)
{
if (List1.SelectedItem != null)
{
Fields fi = (Fields)this.List1.SelectedItem;
// fi.Quantity = txtQuantity.Text;
if (List2.Items.Contains(List1.SelectedItem))
{
MessageBox.Show("Esse item já foi adicionado!");
}
else
{
List2.Items.Add(fi);
MessageBox.Show("Item Adicionado com sucesso!");
}
}
}
My XAML:
<ListBox Name="List1" ItemsSource="{Binding Items}" Hold="holdListAdd">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="78">
<TextBlock Grid.Column="0" Text="{Binding FNome}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Grid.Column="1" Text="{Binding FEstado}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Name="List2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="78">
<TextBlock Grid.Column="0" Text="{Binding FNome}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Grid.Column="1" Text="{Binding FEstado}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>