Помогите реализовать методы для перетаскивания видеофайла из проводника на форму ListView.Информация о размещении видеофайла должна отображаться в GridView ,на выделенной строке ListView в кокретном cтолбце(поле) GridView.
private void ViewAllCards_Drop(object sender, DragEventArgs e)
{
string[] handles = (string[])e.Data.GetData(DataFormats.FileDrop, false);
foreach (string s in handles)
{
if (File.Exists(s))
{
if (string.Compare(System.IO.Path.GetExtension(s), ".avi", true) == 0)
{
AddFileToViewAllCards(s);
}
if (string.Compare(System.IO.Path.GetExtension(s), ".mkv", true) == 0)
{
AddFileToViewAllCards(s);
}
if (string.Compare(System.IO.Path.GetExtension(s), ".mp4", true) == 0)
{
AddFileToViewAllCards(s);
}
if (string.Compare(System.IO.Path.GetExtension(s), ".wtv", true) == 0)
{
AddFileToViewAllCards(s);
}
}
else if (Directory.Exists(s))
{
DirectoryInfo di = new DirectoryInfo(s);
FileInfo[] files = di.GetFiles("*.avi");
foreach (FileInfo file in files)
AddFileToViewAllCards(file.FullName);
}
}
}
public void AddFileToViewAllCards(string fullFilePath)
{
string fileName = System.IO.Path.GetFileName(fullFilePath);
string dirName = System.IO.Path.GetDirectoryName(fullFilePath);
if (dirName.EndsWith(Convert.ToString(System.IO.Path.DirectorySeparatorChar)))
dirName = dirName.Substring(0, dirName.Length - 1);
ViewAllCards.ItemsSource = null;
ViewAllCards.Items.Clear();
ViewAllCards.Items.Add(fileName);
}
private void ViewAllCards_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
{
e.Effects = DragDropEffects.Copy;
}
else
e.Effects = DragDropEffects.None;
}
Ничего не происходит, данные в ListView не отображаются
ViewAllCards.Items.Clear();так вы при добавлении каждого очищаете список. И вообще познакомьтесь с привязками данных и ObservableCollection. А вhandlesчто приходит? – aepot Nov 01 '22 at 22:05<ListView.ItemTemplate>https://ru.stackoverflow.com/a/1116136/373567 илиGridViewс биндингами, я не знаю, что там у вас на самом деле. – aepot Nov 02 '22 at 09:38