Browse Source

Merge pull request #877 from MrDaedra/master

Solved issue #92
pull/933/head
Steven Kirk 9 years ago
committed by GitHub
parent
commit
88d9b58d31
  1. 15
      src/Avalonia.Controls/Window.cs
  2. 26
      src/Windows/Avalonia.Win32/WindowImpl.cs

15
src/Avalonia.Controls/Window.cs

@ -11,6 +11,7 @@ using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.Styling;
using System.Collections.Generic;
using System.Linq;
namespace Avalonia.Controls
{
@ -268,6 +269,10 @@ namespace Avalonia.Controls
using (BeginAutoSizing())
{
var affectedWindows = s_windows.Where(w => w.IsEnabled && w != this).ToList();
var activated = affectedWindows.Where(w => w.IsActive).FirstOrDefault();
SetIsEnabled(affectedWindows, false);
var modal = PlatformImpl.ShowDialog();
var result = new TaskCompletionSource<TResult>();
@ -276,6 +281,8 @@ namespace Avalonia.Controls
.Subscribe(_ =>
{
modal.Dispose();
SetIsEnabled(affectedWindows, true);
activated?.Activate();
result.SetResult((TResult)_dialogResult);
});
@ -283,6 +290,14 @@ namespace Avalonia.Controls
}
}
void SetIsEnabled(IEnumerable<Window> windows, bool isEnabled)
{
foreach (var window in windows)
{
window.IsEnabled = isEnabled;
}
}
/// <inheritdoc/>
void INameScope.Register(string name, object element)
{

26
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -33,7 +33,6 @@ namespace Avalonia.Win32
private IntPtr _hwnd;
private IInputRoot _owner;
private bool _trackingMouse;
private bool _isActive;
private bool _decorated = true;
private double _scaling = 1;
private WindowState _showWindowState;
@ -344,30 +343,9 @@ namespace Avalonia.Win32
public virtual IDisposable ShowDialog()
{
var disabled = s_instances.Where(x => x != this && x.IsEnabled).ToList();
WindowImpl activated = null;
foreach (var window in disabled)
{
if (window._isActive)
{
activated = window;
}
window.IsEnabled = false;
}
Show();
return Disposable.Create(() =>
{
foreach (var window in disabled)
{
window.IsEnabled = true;
}
activated?.Activate();
});
return Disposable.Empty;
}
public void SetCursor(IPlatformHandle cursor)
@ -414,12 +392,10 @@ namespace Avalonia.Win32
{
case UnmanagedMethods.WindowActivate.WA_ACTIVE:
case UnmanagedMethods.WindowActivate.WA_CLICKACTIVE:
_isActive = true;
Activated?.Invoke();
break;
case UnmanagedMethods.WindowActivate.WA_INACTIVE:
_isActive = false;
Deactivated?.Invoke();
break;
}

Loading…
Cancel
Save