1
當我的用戶控件(WindowScreen)第一次加載時,我的elementhost顯示正確。當我實例化usercontrol並傳入一個不同的id時,elementhost不會被更新。有沒有理由爲此或有沒有辦法解決這個問題?如何刷新winform內部的wpf elementhost
這是我的代碼。
WindowScreen.cs - WinForm的:
public partial class WindowScreen : UserControl
{
private WindowView _windowView;
private WindowViewModel _windowViewModel = null;
public WindowScreen(int id)
{
InitializeComponent();
elementHost.Child = this.elementHost1;
_windowViewModel = new WindowViewModel();
_windowView = (WindowView) this.elementHost.Child;
//_windowViewModel.LoadTypes(123); --- first load
_windowViewModel.LoadTypes(id); --- pass in parameter
_windowView.DataContext = _windowViewModel;
}
}
TestScreen.cs - WinForm的:
public partial class TestScreen : UserControl
{
public TestScreen()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WindowScreen ws = new WindowScreen(298);
}
}
我試過你做this.windowScreen =新WindowScreen(298)說。但無濟於事。所以當我點擊Test usercontrol中的按鈕時,我將傳遞一個參數給WindowScreen usercontrol(它有一個元素主體),這是假設更新WindowScreen中的元素主機。我的元素主機(WindowView)仍然沒有更新。任何其他建議? – Calvin 2012-08-08 20:34:01