如何访问项目的名称字段?

时间:2015-05-08 19:11:00

标签: c# wpf xaml

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);
            }
        }

虽然我在ListView中选择了项目,但当我进入foreach循环时,我无法弄清楚如何获取项目的名称字段

1 个答案:

答案 0 :(得分:2)

确保将item变量强制转换为您提供的元素类型ItemsSource。它看起来应该像ShortcutItem那样?通过WPF设计,无法强烈键入ItemsSource属性。

foreach (ShortcutItem item in ItemsOnGrid.SelectedItems) {
     string name = item.Name;
}  
相关问题