簡體   English   中英

wpf ElementHost沒有顯示

[英]wpf ElementHost doesn't show

我對這個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();
    }
}

從您的代碼中看起來您將elementhost子元素設置為Class而不是它的實例(無法編譯)。 我的問題是TestView實例來自哪里?

TestHost.Child = TestView;

要調試,在try / catch塊中更改'ex.ToString()'以顯示消息框; 如果發生異常,您就會意識到這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM