Reputation: 470
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.
Upvotes: 0
Views: 1221
Reputation: 1235
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
Upvotes: 2