wpf在构造函数中使用参数时出现InvalidOperationException

时间:2016-07-15 08:18:35

标签: c# wpf parameters constructor

我需要在MainWindow中有一些参数,如下所示:

    public MainWindow(DbContext _ctx, string dbSetName)
    {
        Type setType = Type.GetType(dbSetName);
        Type gType = typeof(GenericViewModel<>).MakeGenericType(setType);
        var oVM = Activator.CreateInstance(gType);
        this.DataContext = oVM;
        InitializeComponent();
    }

现在我想从另一个项目中显示MainWindow:

var w = new MainWindow (PersonCbContext, "People"

我得到一个例外说:

"The calling thread must be STA, because many UI components require this."

0 个答案:

没有答案