Click here to Skip to main content
14,700,041 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
I want to show all files from a given path, including the icon images or better yet, how can I arrange when should be shown which image ?
As you can see in the list below, there is a word icon for every item in the list (.pdf, .doc, .zip)

Link to image file (this is where i stopped)
Posted
Updated 1-Aug-12 7:03am
v3

This is a very open ended question. You will want to use a ListView a DataTemplate. Bind to a collection in the ViewModel. The collection could be string, and then use a Converter to use the correct template, or you can have a collection that is a class that contains the name of the file and the image (or path to the image.

Here is possible XAML:
<ListBox  ItemsSource="{Binding Path=FileNames}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" >
                <Image Source="{Binding ImagePath}" />
                <TextBlock Text="{Binding FileName}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>


There is still a lot of work to do since you have to create the ViewModel, and fill it.
   
Comments
Kenneth Haugland 1-Aug-12 12:50pm
   
Id rather do this than what the OP marked as an answer. So you got a 5 :)
I found another solution... I replaced the listview with the webbrowser control, it shows direcotry browsing and also the icons od the files, basically thats it, now I just have to do some more tweaking :)
   
Here is a preview of the way I did it (regarding the question)
<listview x:name="listView" selectionmode="Single" scrollviewer.cancontentscroll="True" scrollviewer.verticalscrollbarvisibility="Auto" cursor="Arrow" verticalcontentalignment="Top" mousedoubleclick="listView_MouseDoubleClick" xmlns:x="#unknown">
                    <listview.view>
                        <gridview allowscolumnreorder="False">
                            <gridview.columnheadercontainerstyle>
                                <style>
                                    <!--<Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>-->
                                </style>
                            </gridview.columnheadercontainerstyle>
                            <gridviewcolumn>
                                <gridviewcolumnheader>
                                </gridviewcolumnheader>
                                <gridviewcolumn.celltemplate>
                                    <datatemplate>
                                        <stackpanel orientation="Horizontal">
                                            <image height="40" source="/Slike/word.png" />
                                        </stackpanel>
                                    </datatemplate>
                                </gridviewcolumn.celltemplate>
                            </gridviewcolumn>
                            <gridviewcolumn />
                        </gridview>
                    </listview.view>
                </listview>
   
v2
Ive answerd a simular question yesterday, and you can see it here:
WPF ObservableCollection problem[^]

That was however just for the Image (Icon in your case), MAke one more property in the ImageDAta Class were the name of the file is displayed and you should have a working sample.

Happy coding :)
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900