0

I am trying to make a media player like VLC in C#. I want to display the name of the file on the title window which is currently loaded. I don't know how to do it. I have searched a lot about it but i was not able to get the right answer from the links Set a taskbar text different from the Window title in wpf and can I add text box beside the title of WPF window.

I have also problem in fetching the name of the file. when fetching the name of the file, i am getting the whole path not only the name of the file. I am not getting the idea from the link How to get only filenames within a directory using c#?

 mediaElement.Source = new Uri(loadfile.FileName);
 this.Title =loadfile.FileName;

now the file name id not the file name but the complete path. How to get only the name of the file. Any help is appreciable.

Community
  • 1
  • 1

2 Answers2

0

You can bind window title to a property in code behind. for instance :

<Window title={Binding ToMyProperty} /> etc...
Marcin
  • 427
  • 7
  • 21
0

To get the file name from a file path, you can use the Path.GetFileName method which is in System.IO namespace. This will return the file name from the provided path.

I have modified the example you provided, to do what you described:

mediaElement.Source = new Uri(loadfile.FileName);
this.Title = System.IO.Path.GetFileName(loadfile.FileName);

Hope that helps.

Brad
  • 554
  • 4
  • 7