/// <summary>
 /// Sets attributes to control how visual styles are applied to a specified window.
 /// </summary>
 /// <param name="window">The window.</param>
 /// <param name="attr">The attributes to apply or disable.</param>
 /// <param name="enable">if set to <c>true</c> enable the attribute, otherwise disable it.</param>
 public static void SetWindowThemeAttribute(this IWin32Window window, NativeMethods.WindowThemeNonClientAttributes attr, bool enable = true)
 {
     NativeMethods.WTA_OPTIONS ops = new NativeMethods.WTA_OPTIONS();
     ops.Flags = attr;
     ops.Mask  = enable ? (uint)attr : 0;
     try { NativeMethods.SetWindowThemeAttribute(window.Handle, NativeMethods.WindowThemeAttributeType.WTA_NONCLIENT, ref ops, Marshal.SizeOf(ops)); }
     catch (EntryPointNotFoundException) { }
     catch { throw; }
 }
Exemple #2
0
        public override void OnApplyTemplate()
        {
            VerifyContextAndObjectState( );

            base.OnApplyTemplate();

            // base actually changed something.  sniff
            // around to see if there are any framelet
            // objects we need to hook up.

            // Get the root element of the style
            FrameworkElement root = (this.GetVisualChild(0)) as FrameworkElement;

            if (_navigationService != null)
            {
                _navigationService.VisualTreeAvailable(root);
            }

            // did we just apply the framelet style?
            if ((root != null) && (root.Name == "NavigationBarRoot"))
            {
                if (!_fFramelet)
                {
                    // transitioning to Framelet style

                    // Use Window property for this once available
                    // turn off drawing of title in window header
                    // This is tracked in task # 12401.

#if WCP_SYSTEM_THEMES_ENABLED
                    NativeMethods.WTA_OPTIONS wo = new NativeMethods.WTA_OPTIONS();
                    wo.dwFlags = (NativeMethods.WTNCA_NODRAWCAPTION | NativeMethods.WTNCA_NODRAWICON | NativeMethods.WTNCA_NOSYSMENU);
                    wo.dwMask  = NativeMethods.WTNCA_VALIDBITS;

                    // call to turn off theme parts
                    UnsafeNativeMethods.SetWindowThemeAttribute(new HandleRef(this, Handle), NativeMethods.WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT, wo);
#endif // WCP_SYSTEM_THEMES_ENABLED
                    _fFramelet = true;
                }
            }
            else
            {
                if (_fFramelet)
                {
                    // Use Window property for this once available
                    // turn on drawing of title in window header

#if WCP_SYSTEM_THEMES_ENABLED
                    NativeMethods.WTA_OPTIONS wo = new NativeMethods.WTA_OPTIONS();
                    wo.dwFlags = 0;
                    wo.dwMask  = NativeMethods.WTNCA_VALIDBITS;

                    // call to turn off theme parts
                    UnsafeNativeMethods.SetWindowThemeAttribute(new HandleRef(this, Handle), NativeMethods.WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT, wo);
#endif // WCP_SYSTEM_THEMES_ENABLED

                    // no longer in framelet mode
                    _fFramelet = false;
                }
            }
        }