Using RibbonWindow to implement a status tray application

Ribbon for WPF Forum

Posted 6 years ago by Karen Johnson
Version: 17.2.0661
Platform: .NET 4.5
Environment: Windows 10 (64-bit)
Avatar

I am using the RibbonWindow for a status tray application, so when the user clicks the Close button, the window needs to be hidden and not displayed in the task bar.  I'm seeing that the contents of the application are hidden, but the border of the app is still visible and I am able to resize the window.  I was able to reproduce it on a test project with an empty RibbonWindow and the code below.  Is there something else I need to set specifically for the RibbonWindow?

Thanks!
KC

public partial class MainWindow
{
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

/// <summary>
/// Win32 API Constants for ShowWindowAsync()
/// </summary>
private const int SW_HIDE = 0;
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;

private IntPtr _mainWindow = IntPtr.Zero;

public MainWindow()
{
InitializeComponent();

this.Show();

var me = Process.GetCurrentProcess();
_mainWindow = me.MainWindowHandle;
}

private void MainWindow_OnClosing(object sender, CancelEventArgs e)
{
ShowWindowAsync(_mainWindow, SW_HIDE);
e.Cancel = true;
}
}

Comments (2)

Posted 6 years ago by Karen Johnson
Avatar

After some further digging around, it is the ActiproWindowChromeShadow that is still visible.  I would expect it to be set to hidden when the window is set to SW_HIDE.

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

That is the outer glow used in the WindowChrome for the Metro theme.  It's not detecting that you are hiding its parent window via Windows API so it never hides.  

Here's some code to toggle its visibility:

var chrome = WindowChrome.GetChrome(this);
if (false.Equals(chrome.HasOuterGlow))
	chrome.HasOuterGlow = null;
else
	chrome.HasOuterGlow = false;

Set it to false to hide it (do this in your OnClosing handler) and back to null later when the window becomes visible to let the theme decide if outer glow is used (only Metro themes use it).  


Actipro Software Support

The latest build of this product (v24.1.3) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.