Focus Problem with WPF ContentControl

Hi,

at the moment I’m working on some focus problems at our main application.
Here we use Hydra a lot to mix Delphi and .Net dialogs.

And I think I found a problem with hydra. I’m not really sure if it is hydra wich is causing the problem but at the moment it looks like.

To test this I used the VisualizerHost project at the delphi samples and added another Button to it which simply opens a Window with only one VisualPlugin inside.

<hydra:VisualPlugin x:Class="Visualizer.TestView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hydra="clr-namespace:RemObjects.Hydra.WPF;assembly=RemObjects.Hydra.WPF"
Height="300" Width="300"
>
<ContentControl>
    <Rectangle Fill="GreenYellow"></Rectangle>
</ContentControl>

And I created a new WPF-Application with a red rectangle in it.

<Window x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp1"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Grid>
    <Rectangle Fill="Red"></Rectangle>
</Grid>

If I open the delphi app and the green window and close it everything is working fine.
But if I open the green window switch to the red one, back to the green one and close it then the red one comes infront of the delphi app.

Here is a video:

As additional info this happens only when the green rectangle is inside a ContentControl. So the problem is the ContentControl or any descedant (Frame in my main app).
And the second app (red window) has to be an WPF app. Otherwise it doesn’t work for me.

Can you please have a look at it and maybe fix it if it’s a bug?

Hi,

can you create a simple testcase that reproduces this issue, pls?
you can attch it here or drop email to support@
what delphi version you are using?

Sure, here is a sample.
Sample.zip (213.2 KB)
I’m using Delphi 10.3.2 and Visual Studio 2017 with .Net 4.8.

Hi,

you can use this temporary workaround:

procedure TMainForm.Button1Click(Sender: TObject);
var
 Window: TForm1;
begin
   Window := TForm1.Create(nil);
   Window.ShowModal;
   Self.BringToFront;  //<<<<< added
   Window.Free;
end;

Hi,

thanks for the workaround. It is working but I don’t want to call it for every dialog with can have a visual plugin.
So what do you mean by temporary?

Hi,

we are still investigating this issue.
the final fix can be a differ

Hi,

are there any updates to this topic?
Did you find a fix for it?

Hi,

this issue isn’t solved yet

Hi,

we can’t control forms that uses ShowModal from visual plugins.

as an another workaround:

  • pass form as the owner to child form:
var
 Window: TForm1;
begin
   Window := TForm1.Create(self);  //<<< changed `nil` to `self`
   Window.ShowModal; 
   Window.Free;
  • in child form add OnHide event and code like
procedure TForm1.FormHide(Sender: TObject);
begin
  if Assigned(Owner) and (Owner is TForm) then
    TForm(Owner).BringToFront;
end;

or use old workaround:

procedure TMainForm.Button1Click(Sender: TObject);
var
 Window: TForm1;
begin
   Window := TForm1.Create(nil);
   Window.ShowModal;
   Self.BringToFront;  //<<<<< added
   Window.Free;
end;