gpt4 book ai didi

winforms - "Illegal characters in path."Visual Studio WinForm 设计 View

转载 作者:行者123 更新时间:2023-12-03 22:32:10 25 4
gpt4 key购买 nike

我正在为 WinForms 项目组合一个轻量级 MVP 模式。一切都编译并运行良好。但是,当我尝试在 Visual Studio 中以设计模式打开 WinForm 时,出现“ 路径中的非法字符”错误。我的 WinForm 使用泛型并继承自基本 Form 类。在 WinForm 中使用泛型有问题吗?

这是 WinForm 和基本 Form 类。

public partial class TapsForm : MvpForm<TapsPresenter, TapsFormModel>, ITapsView
{
public TapsForm()
{
InitializeComponent();
}

public TapsForm(TapsPresenter presenter)
:base(presenter)
{
InitializeComponent();
UpdateModel();
}

public IList<Taps> Taps
{
set { gridTaps.DataSource = value; }
}

private void UpdateModel()
{
Model.RideId = Int32.Parse(cboRide.Text);
Model.Latitude = Double.Parse(txtLatitude.Text);
Model.Longitude = Double.Parse(txtLongitude.Text);
}
}

基本形式 MvpForm:
public class MvpForm<TPresenter, TModel> : Form, IView
where TPresenter : class, IPresenter
where TModel : class, new()
{
private readonly TPresenter presenter;
private TModel model;

public MvpForm()
{
}

public MvpForm(TPresenter presenter)
{
this.presenter = presenter;
this.presenter.RegisterView(this);
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (presenter != null)
presenter.IntializeView();
}

public TModel Model
{
get
{
if (model == null)
throw new InvalidOperationException("The Model property is currently null, however it should have been automatically initialized by the presenter. This most likely indicates that no presenter was bound to the control. Check your presenter bindings.");

return model;
}
set { model = value;}
}
}

最佳答案

This post helped answer my question.

显然,这是 Visual Studio 中的一个限制。我能够通过定义通用值的中间类来解决它。它是 周围真的很难看 ,但我现在可以在 Visual Studio 中打开该表单。

这是我的中间类,它必须在一个单独的文件中,或者在表单类定义之后。它还必须有一个默认构造函数,隐式或显式:

public class MvpTapsForm : MvpForm<TapsPresenter, TapsFormModel>
{
}

然后在我的实际表单中,我从 MvpTapsForm 继承。
public partial class TapsForm : MvpTapsForm, ITapsView
{
public TapsForm()
{
InitializeComponent();
}

public TapsForm(TapsPresenter presenter)
: base(presenter)
{
InitializeComponent();
UpdateModel();
}

public IList<Taps> Taps
{
set { gridTaps.DataSource = value; }
}

private void UpdateModel()
{
Model.RideId = Int32.Parse(cboRide.Text);
Model.Latitude = Double.Parse(txtLatitude.Text);
Model.Longitude = Double.Parse(txtLongitude.Text);
}
}

关于winforms - "Illegal characters in path."Visual Studio WinForm 设计 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2546699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com