When my usercontrol(WindowScreen) loads for the first time, my elementhost displays correctly. When I instantiate the usercontrol and pass in a different id, the elementhost doesnt get updated. Is there a reason why for this or is there a way to fix this?
Here’s my code.
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);
}
}
When you call this:
You’re creating a new
WindowScreen, but never setting it to be used in yourTestScreencontrol. You need to overwrite the currentWindowScreenwith this one – something like: