Reputation: 7605
XAML:
<ListView ItemsSource="{Binding ShortcutItems}" x:Name="ItemsOnGrid" View="{StaticResource ImageDetailView}" SelectionMode="Multiple">
</ListView>
C#
foreach (var item in ItemsOnGrid.SelectedItems)
{
string sourceFile = path + @"\" + item;
string destFile = @"H:\Desktop";
if (Directory.Exists(@"H:\Desktop"))
{
File.Copy(sourceFile, destFile, true);
}
}
Although I have items selected in my ListView, when I enter the foreach loop, I can't figure out how to get the Name field of item
Upvotes: 0
Views: 39
Reputation: 27085
Make sure you cast the item
variable to the type of element you are providing as ItemsSource
. It looks that that should be something like ShortcutItem
? By WPF design, there is no way to strongly type the ItemsSource
property.
foreach (ShortcutItem item in ItemsOnGrid.SelectedItems) {
string name = item.Name;
}
Upvotes: 2