我对这个ElementHost
事情有很多问题。有人可以看看我有什么,让我知道发生了什么或为什么没有显示?一切似乎都有效,只是我无法在屏幕上看到ElementHost
显示/刷新(用户控件)。
Test.cs.designer
this.TestHost.Dock = System.Windows.Forms.DockStyle.Fill;
this.TestHost.Location = new System.Drawing.Point(5, 5);
this.TestHost.Name = "TestHost";
this.TestHost.Size = new System.Drawing.Size(1139, 213);
this.TestHost.TabIndex = 1;
this.TestHost.Text = "elementHost1";
this.TestHost.Child = this.testview1;
this.TestHost.Visible = true;
test.cs中
private void btnTest_Click(object sender, EventArgs e)
{
LoadView(item);
}
public void LoadView(Person item)
{
TestHost.Child = this.testview1; //name given when drag/drop .. should still reference wpf TestView xaml
try
{
if (item != null)
{
// TestView is WPF xaml/View
TestView view = new TestView();
view = (TestView) TestHost.Child;
//TestViewModel is a viewmodel
TestViewModel vm = (TestViewModel) view.DataContext;
//load items from viewmodel
vm.LoadItems(item);
}
TestHost.Visible = true;
}
catch(Exception ex)
{
ex.ToString();
}
}
答案 0 :(得分:1)
从您的代码中看起来您将elementhost子元素设置为Class而不是它的实例(无法编译)。我的问题是 TestView实例来自哪里?
TestHost.Child = TestView;
要调试,在try / catch块中更改'ex.ToString()'以显示消息框;如果发生异常,您就会意识到这一点。