I want to Drag and Drop Item between Listbox. One is located in MainWindow and one in UserControl. Tab control items are dynamically coded.([VideoListing], [AddTab, AddItem]) I'm curious if this works and then give me directions.
This is what I wanted. enter image description here
And, this is my Codes
Mainwindow.xaml
<TabControl x:Name="scenarioCB" ItemsSource="{Binding}" Grid.Row="1" HorizontalAlignment="Stretch" Margin="5,0,5,5" VerticalAlignment="Stretch" SelectionChanged="ScenarioCB_SelectionChanged">
<TabControl.ItemTemplate>
<DataTemplate DataType="local:AddTab">
<TextBlock Text="{Binding Header}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate DataType="local:AddTab">
<ListBox x:Name="listBox" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" ItemsSource="{Binding Data}" AllowDrop="True" Drop="ListBox_Drop" DragEnter="ListBox_DragEnter" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Visible">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<MediaElement Margin="3" Source="{Binding Path}" Height="64" Stretch="Uniform" IsMuted="True"/>
<TextBlock Margin="3" Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
Mainwindow.xaml.cs
var tabs = new ObservableCollection<AddTab>();
for (int i = 0; i < DateListCount; i++)
{
var tab = new AddTab();
tab = new AddTab() { Header = DateList[i] + " - " + TimeList[i] };
tab.Data.Add(new AddData() { TIME = TimeList[i] });
Console.WriteLine("i = {0}, Header = {1}, Time = {2}", i, DateList[i], TimeList[i]);
tabs.Add(tab);
}
DataContext = tabs;
AddTab.cs
class AddTab
{
public string Header { get; set; }
public string Time { get; set; }
public ObservableCollection<AddData> Data { get; } = new ObservableCollection<AddData>();
}
AddData.cs
class AddData
{
public string NAME { get; set; }
public string PATH { get; set; }
}
VideoPanel.xaml
<ListBox Grid.Row="0" x:Name="listBox" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" AllowDrop="True" Drop="ListBox_Drop" DragEnter="ListBox_DragEnter" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<MediaElement Margin="3" Source="{Binding Path}" Height="64" Stretch="Uniform" IsMuted="True"/>
<TextBlock Margin="3" Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
VideoPanel.xaml.cs
list.Add(new VideoListing()
{
Name = file_name,
Path = file,
});
VideoListing.cs
class VideoListing
{
public string Name { get; set; }
public string Path { get; set; }
}
If you have an example, please post the link.
Drag and Drop between listbox(MainWindow - UserControl)
Tabitems are dynamic coded