0

I have a ComboBox in which i want to display the names of files in a certain folder.

<ComboBox ItemsSource="{Binding Path=Jobs}" DisplayMemberPath="Name"/>

The bound property Jobs is of type List<FileInfo> which i thought was the most appropriate type to store this kind of information in. A simple Directory.GetFiles gets all the files from the given directory in an array which LINQ-Magic transforms into a List<FileInfo>.

By default the ComboBox now displays the full path to the files. With the DisplayMemberPath="Name" parameter i get the ComboBox to display only the name of the file and the extension.

What do i have to do to get the ComboBox to display only the filename like Path.GetFileNameWithoutExtension() would give me?

I want to avoid changing Jobs to List<Tuple<string,string>> or something like that to store the filename and the folder in different variables.

1
  • 2
    Either use an IValueConverter or change your list items to a custom object with additional properties
    – Fede
    Nov 9, 2015 at 15:18

1 Answer 1

2

IF it's about visual requirment and you don't want to change your items Source use a converter and there you can format your name as you want

1
  • Thank you. Converter was just the thing i was looking for!
    – sebingel
    Nov 9, 2015 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.