Pergunta

I have a wpf usercontrol that contains an activex control housed in a windowsformhost. I'm using an MVVM pattern that says ViewModel1 is mapped to a Pure WPF View and ViewModel2 is mapped to wpf content and the above usercontrol

If ViewModel2 is "Hidden" and then becomes Visible then the Activex control inside it doesn't show (Specifically I'm talking about the VLC activex control).

I've tested in a non MVVM pattern with a button and the usercontrol. The usercontrol is hidden until you press the button and the same thing happens but if I create a method in the usercontrol to re attach the activex control to the windowsformhost then it reappears. If I call this method from a viewmodel then it still remains blank. Does anyone know how I can get this to show again?

EDIT - I've just discovered it's because I have transparency on in my wpf application. It seems it's not possable to do what I want with windowsformshost and transparency enabled.

Foi útil?

Solução

As there are no obvious answers I'll share my experience. When transparency is turned on in the wpf window then the windows form host doesn't refresh when changing from Hidden to Visable. I have found no way to make this work unless it is hosted in a new window with "Allowstransparency=false".

Outras dicas

How are you setting up your active x control? The following Typically works for me in WPF if you are just needing it to attach to a grid. No user control required.:

//Active X Control initializer
private Ax addAxObject<Ax>(Grid container)  
    where Ax : System.Windows.Forms.Control, new() 
{ 
    Ax ax = new Ax();
    var hoster = new System.Windows.Forms.Integration.WindowsFormsHost(); 
    hoster.Child = (System.Windows.Forms.Control)ax; 
    container.Children.Add(hoster); 
    return ax; 
}

private MyActiveXControl myActiveXControl;

public Grid InitializeActiveX(Grid grid)
{
    myActiveXControl = addAxObject<myActiveXControl>(grid);

    return grid;
}

Then all you do is is add it to your grid in your main window like so:

public MainWindow()
{
    InitializeComponent();

    //initialize Active X control
    gridMain = InitializeActiveX(gridMain);
}

It shows up just fine for me. (Obviously not in the designer since it is programatically created)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top