c# - 在 WPF 文本框中显示 "current working directory"

标签 c# wpf binding textbox

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

我不明白如何绑定(bind)它。

最佳答案

  1. ViewModel/View 的后台代码:

    public string CurrentDirectoryPath
    {
       get 
       { 
           return Environment.CurrentDirectory;
       }
    }
    
  2. 在 View 的 XAML 中:

    <TextBox Text="{Binding CurrentDirectoryPath}" />
    
  3. 设置正确的DataContext

    // If you are using MVVM:
    var view = new MyView { DataContext = new MyViewModel() };
    

关于c# - 在 WPF 文本框中显示 "current working directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8715993/

相关文章:

c# - RabbitMQ 中的消息持久化

c# - 为什么我这里有锁?

wpf - 本地 WPF C# 编程

wpf - 如何将 TabControl 的选定值(标题)绑定(bind)到 View 模型上的属性

c# - 如何通知父类有关属性更改

wpf - 使用带有多个绑定(bind)的 StringFormat 的 Multibinding 的较短 xaml 语法是什么?

c# - 一个后台工作线程和多个进度条

c# - 将 JsonDictionary 属性应用于字典

c# - 如何扩展 WPF 路径控件

c# - 在 wpf 中设置与窗口标题不同的任务栏文本