在WPF TextBox中显示"当前工作目录"

Lau*_*ald 4 c# wpf binding textbox

请问有人请告诉我如何使用C#和WPF在文本框中显示当前工作目录的路径?

我不明白我怎么能绑定它.

sll*_*sll 9

  1. 在ViewModel/View的代码背后:

    public string CurrentDirectoryPath
    {
       get 
       { 
           return Environment.CurrentDirectory;
       }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在View的XAML中:

    <TextBox Text="{Binding CurrentDirectoryPath}" />
    
    Run Code Online (Sandbox Code Playgroud)
  3. 设置权限DataContext

    // If you are using MVVM:
    var view = new MyView { DataContext = new MyViewModel() };
    
    Run Code Online (Sandbox Code Playgroud)