无法理解 wpf visual studio 设置

Have trouble understanding wpf visual studio setup

我有一个由 visual studio 设置的 wpf 项目。我正在尝试创建 MVP 类,但我无法访问我创建的这些 类 中的任何 xaml 属性(例如 textBox1.text 或 label.Content)

他们给我的文件是 MainWindow.xaml.cs、MainWindow.xaml 和其他一些文件。我可以访问 MainWindow.xaml.cs 中的那些 xaml 属性。但是在我的 view.cs 中它显示 'textBox' does not exist in the current content。感谢任何额外的细节和信息

MainWIndow.xaml.cs:

namespace myApp
{
public partial class MainWindow : Window
{
    private Model model;
    public MainWindow()
    {
        InitializeComponent();
        //initialize the storage
        model= new Model();
    }

    /// <summary>
    /// clear the textbox for user input
    /// </summary>
    private void clearInput()
    {
        textBox1.Text = ""; //these works fine
        textBox2.Text = "";
        textBox3.Text = "";
    }

[...]
}

view.cs:

namespace myApp
{
public interface IView
{
    void clearInput();
}

public class PView: IView
{
    public void clearInput()
    {
        textBox1.Text = ""; //error
        textBox2.Text = "";
        textBox3.Text = "";
    }
 }

您需要为 XAML 文件中的控件(文本框等)命名,如下所示

<TextBlock Name="textblock1" .....

然后在您的代码文件中您可以访问 textblock1

编辑

但是,这些控件始终是私有的,因此对其他人不可见 类。要使数据 public 你需要尝试这样的事情:

public string TextBlockText
{
   get { return textblock1.Text; }
}

然后在你的另一个 类 你可以使用

var text = MainWindow.TextBlockText;

EDIT2

或者,您可以像这样public制作这些控件

<TextBox x:Name="textBox1" x:FieldModifier="public" />