Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display "current working directory" in WPF TextBox

Could someone please tell me how to display the path of the current working directory in a textbox using C# and WPF?

I don't understand how I can bind to it.

like image 528
Laufried Wiesewald Avatar asked Dec 22 '22 04:12

Laufried Wiesewald


1 Answers

  1. In ViewModel/View's code behind:

    public string CurrentDirectoryPath
    {
       get 
       { 
           return Environment.CurrentDirectory;
       }
    }
    
  2. In View's XAML:

    <TextBox Text="{Binding CurrentDirectoryPath}" />
    
  3. Setup right DataContext

    // If you are using MVVM:
    var view = new MyView { DataContext = new MyViewModel() };
    
like image 196
sll Avatar answered Dec 24 '22 02:12

sll