1
votes

I have the below code in a usercontrol.

 <Grid>
        <Popup x:Name="MyPopup" IsOpen="true" AllowsTransparency="True" HorizontalOffset="0" VerticalOffset="500">
            <Border VerticalAlignment="Top" Height="500" Width="440">
                <Keyboard:Keyboard x:Name="Keyboard"/>
            </Border>
        </Popup>
 </Grid>

The custom keyboard on Popup works normal in WPF application.

But when the same usercontrol is hosted in winforms using ElementHost and a SaveFileDialog is opened in this context,the Popup doesn't get the focus.

Now that I have a keyboard on the Popup,its kinda obsolete in this situation.

Any suggestions/ideas/hacks to get the focus on the Popup? Or is it possible to achieve this in Winforms?

1

1 Answers

1
votes

I suppose it doesn't get the focus because ShowDialog is blocking and therefore your window cannot receive any event while the dialog is displayed.

A possible workaround would be to display the dialog from another STA thread.

var dialog = new SaveFileDialog();
var thread = new Thread(() => dialog.ShowDialog());
thread.SetApartmentState(ApartmentState.STA);
thread.Start();