【发布时间】:2016-05-11 15:48:50
【问题描述】:
我有一个由 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 = "";
}
}
【问题讨论】:
-
我猜你需要做额外的工作和阅读以了解你需要做什么(开箱即用,不会为 MVP 设置 XAML 和 cs 文件, MVC、MVVM 或其他任何东西)。考虑到它的年龄,不确定这是否会有所帮助:Using the Model-View-Presenter (MVP) Design Pattern to enable Presentational Interoperability and Increased Testability
标签: c# wpf visual-studio-2010 xaml