Im using the following code for drag and drop and the following statement
return null when I checked it in the debug,what is wrong here?
var mySelectedItem = listbox1.SelectedItem as ListBoxItem;
public MainWindow()
{
InitializeComponent();
_UsersList.Add(new User {Name = "Mike"});
_UsersList.Add(new User { Name = "Nick" });
listbox1.ItemsSource = _UsersList;
}
public ObservableCollection<User> userList{
get { return _UsersList; }
}
private void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0 && string.IsNullOrEmpty(textbox1.Text))
{
if (listbox1.SelectedItems.Count > 0)
{
var mySelectedItem = listbox1.SelectedItem as ListBoxItem;
if (mySelectedItem != null)
{
DragDrop.DoDragDrop(listbox1, mySelectedItem.Content.ToString(), DragDropEffects.Copy);
}
}
}
}
the xaml is
<ListBox x:Name="listbox1" HorizontalAlignment="Left" Height="115" Margin="100,75,0,0"VerticalAlignment="Top" Width="150" ItemsSource="{Binding userList}"
SelectionChanged="listbox1_SelectionChanged" >