“路径中的非法字符". Visual Studio WinForm设计视图 [英] "Illegal characters in path." Visual Studio WinForm Design View

查看:112
本文介绍了“路径中的非法字符". Visual Studio WinForm设计视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为WinForms项目构建一个轻量级的MVP模式.一切都可以编译并正常运行.但是,当我尝试在Visual Studio中以设计模式打开WinForm时,出现"路径中的非法字符"错误.我的WinForm使用泛型并从Form的基类继承.在WinForm中使用泛型是否有问题?

I am putting together a lightweight MVP pattern for a WinForms project. Everything compiles and runs fine. However when I attempt to open the WinForm in design mode in Visual Studio I get a "Illegal characters in path" error. My WinForm is using generics and inheriting from a base Form class. Is there a problem with using generics in a WinForm?

这是WinForm和基本Form类.

Here is the WinForm and base Form class.

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:

Base form 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;}
    }
}

推荐答案

显然,这是Visual Studio中的一个限制.我可以通过定义一个通用值的中间类来解决此问题. 确实很难解决,但是我现在可以在Visual Studio中打开表单.

Apparently, this a limitation in Visual Studio. I was able to work around it by having an intermediary class that defined the generic values. It a really ugly work around, but I can now open the form in Visual Studio.

这是我的中介类,它必须位于单独的文件中,或者位于表单类定义之后.它还必须具有默认的构造函数,隐式或显式:

Here is my intermediary class, which has to be either in a seperate file, or AFTER the form class definition. It must also have a default constructor, implicit or explicit:

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

然后以我的实际形式继承自MvpTapsForm.

Then in my actual form I inherit from 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);
    }
}

这篇关于“路径中的非法字符". Visual Studio WinForm设计视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆