I am using WPF elementhost in Winforms. The scenario is , I am having one UserControl. With the visibility of the UserControl I am adding and disposing elementhost. When the visibility is false the elementhost is disposed and again when UserControl gains visibility I am adding elementhost. At this point only I am getting this exception.
If I set the elementhost to null instead of Dispose means, it works. So Dispose method causes exception.Whether it might be belongs to some handle problem? Because the elementhost parent is not disposed. And again I am adding new element host to that particular parent.
private void AddingElementHost()
{
// create an element host
var host = new ElementHost();
host.BackColor = Color.Red;
//Exception occurs at this point.
this.tabPageAdv1.Controls.Add(host);
}
private void RemovingElementHost()
{
if(tabPageAdv1.HasChildren)
{
ElementHost host = tabPageAdv1.Controls[0] as ElementHost;
if (host != null)
{
//Dispose the element host to avoid memory leak
host.Dispose();
}
this.tabPageAdv1.Controls.Clear();
}
}
Aucun commentaire:
Enregistrer un commentaire