我对这个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();
}
}发布于 2012-07-30 08:44:30
从您的代码来看,您将您的elementhost子程序设置为一个类,而不是它的一个实例(它不会编译)。我的问题是 TestView实例来自哪里?
TestHost.Child = TestView;要进行调试,在try/catch块中更改'ex.ToString()‘以显示消息框;如果出现异常,您将注意到它。
https://stackoverflow.com/questions/11691778
复制相似问题