C# 如何在winform中刷新wpf elementhost
当我的usercontrol(WindowsScreen)第一次加载时,我的elementhost显示正确。当我实例化usercontrol并传入不同的id时,elementhost不会得到更新。这是有原因的还是有办法解决的 这是我的密码 WindowsScreen.cs--winform:C# 如何在winform中刷新wpf elementhost,c#,wpf,C#,Wpf,当我的usercontrol(WindowsScreen)第一次加载时,我的elementhost显示正确。当我实例化usercontrol并传入不同的id时,elementhost不会得到更新。这是有原因的还是有办法解决的 这是我的密码 WindowsScreen.cs--winform: public partial class WindowScreen : UserControl { private WindowView _windowView; private Windo
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;
}
}
public partial class TestScreen : UserControl
{
public TestScreen()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WindowScreen ws = new WindowScreen(298);
}
}
TestScreen.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;
}
}
public partial class TestScreen : UserControl
{
public TestScreen()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WindowScreen ws = new WindowScreen(298);
}
}
当你称之为:
WindowScreen ws = new WindowScreen(298);
您正在创建新的窗口屏幕
,但从未将其设置为在测试屏幕
控件中使用。您需要用此屏幕覆盖当前的窗口屏幕
——类似于:
// This needs to be the appropriate/correct variable
this.windowScreen1 = new WindowScreen(298);
我已经试过你说的了。windowScreen=新windowScreen(298);但是没有用。因此,当我单击TestUserControl中的按钮时,我将向WindowsScreen用户控件(它有一个elementhost)传递一个参数,这将更新WindowsScreen中的elementhost。我的elementhost(WindowView)仍然没有更新。还有其他建议吗?