0

My datagrid's ItemSource is set in the constructor as

dataGridShortcuts.ItemsSource = new DirectoryInfo(@"X:\Shortcuts").GetFiles();

My first problem is that there are too many columns being displayed. I am only interested in the name of the file and it's associated image.

<DataGrid x:Name="dataGridShortcuts" FontSize="16" CanUserDeleteRows="False" AutoGenerateColumns="False">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Shortcut Name" />
        </DataGrid.Columns>
        <DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <Image Height="100" />
            </DataTemplate>
        </DataGrid.RowDetailsTemplate>
    </DataGrid>

I think my XAML is wrong and I'm not sure how I can fix it.

After turning off AutoGenerate, I get a list of nothing. Please help me bind or get the file name into "Shortcut Name" and Icon for that name into the image

I updated the XAML

leppie
  • 115,091
  • 17
  • 196
  • 297
software is fun
  • 7,286
  • 18
  • 71
  • 129
  • To disable auto column creation set `` which should only leave your _Shortcut Name_ column. As for the image `FileInfo` does not provide `FileImage` property – dkozl May 06 '15 at 13:46
  • so do i need to create another class to associate the two? (Icon with FileName) or is there a better way to do this? – software is fun May 06 '15 at 14:18
  • You don't need another class. You can do it with custom `IValueConverter` which will convert bound `FullName` property to `ImageSource` like in [this](http://stackoverflow.com/questions/1325625/how-do-i-display-a-windows-file-icon-in-wpf) question – dkozl May 06 '15 at 14:22
  • Thanks but now I dont get the file name or image in the DataGrid after turning off AutoGenerate – software is fun May 06 '15 at 14:26
  • To show file name you need to bind [`Name`](https://msdn.microsoft.com/en-us/library/system.io.fileinfo.name(v=vs.110).aspx) or [`FullName`](https://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.fullname(v=vs.110).aspx) (depends on what you want to show) and not `FirstName` as you do at the moment – dkozl May 06 '15 at 14:28

0 Answers0