Reputation: 1555
I have a WPF application with two xaml windows from two different dlls. Both Dlls load at the same time and display their windows which works fine. There is also another window of a third party software.
Please note that all windows are borderless (windowstyle = none).
My problem is that I want the focus to remain with one of the two xaml windows. As soon as the focus goes to the third party software window, I want any one of the xaml window to regain it. How can I achieve this? Maybe in OnDeactivate event?
public void OnMainGUIDEactivate(object sender, EventArgs e)
{
Activate();
}
// Tried to add application deactivate
public MyFirstView()
{
InitializeComponent();
Application.Current.Deactivated += AppDeactivated;
}
void AppDeactivated(object sender, EventArgs e)
{
// Application deactivated
Activate();
}
Upvotes: 0
Views: 712
Reputation: 1555
I resolved this problem by a work around.
On both xamls I used Topmost="True"
Upvotes: 0
Reputation: 1891
There's a MVVM / Blend approach:
Declare this on your window:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
Then call the focus method on Deactivated event of your window
<i:Interaction.Triggers>
<i:EventTrigger EventName="Deactivated" >
<ei:CallMethodAction MethodName="Focus" TargetObject="{Binding ElementName=mywindow}" />
</i:EventTrigger>
</i:Interaction.Triggers>
Upvotes: 0
Reputation: 17858
The event you're after is : Application.Current.Deactivated
you can then call it to reactivate, so you can then call either of your forms with whatever.Activate()
and it will bring it back
Upvotes: 1