سؤال

Just like the Fluent.RibbonWindow, I need controls to stick on my window's caption/borders.
I tried extracting the RibbonWindow from the class, but I always run into trouble. I just can't do it...
Can someone help me with this?
I basically need to extend my window's client area to the whole window.
I need to extend the client area into the frame, not the frame into the client area!

هل كانت مفيدة؟

المحلول

The custom chrome feature allows applications control over the outer frame of the window so that WPF content can be drawn over the title bar.

That sounds like what you are looking for: WPF Shell Integration Library

نصائح أخرى

I have once added an Outlook-style button to the non-client area by placing it in a frameless, topmost and transparent window.

This is the base class which that window inherited:

public class WindowHeaderButton : Window
{
    private readonly Window _owner;

    public WindowHeaderButton(Window owner)
    {
        _owner = owner;
        _owner.Loaded += owner_Loaded;
        _owner.LocationChanged += owner_LocationChanged;
        _owner.StateChanged += owner_StateChanged;
        _owner.SizeChanged += owner_SizeChanged;
        _owner.Deactivated += _owner_Deactivated;
        _owner.Activated += _owner_Activated;
        Activated += WindowHeaderButton_Activated;
        SizeToContent = SizeToContent.WidthAndHeight;
        WindowStyle = WindowStyle.None;
        AllowsTransparency = true;
        Background = new SolidColorBrush(Colors.Transparent);
        ShowInTaskbar = false;
    }

    void WindowHeaderButton_Activated(object sender, System.EventArgs e)
    {
        Opacity = 1;
    }

    void _owner_Activated(object sender, System.EventArgs e)
    {
        Opacity = 1;
    }

    void _owner_Deactivated(object sender, System.EventArgs e)
    {
        Opacity = 0.75;
    }

    private void owner_Loaded(object sender, RoutedEventArgs e)
    {
        Owner = _owner;
        Show();
        UpdatePosition();
    }

    private void owner_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        UpdatePosition();
    }

    private void owner_StateChanged(object sender, System.EventArgs e)
    {
        UpdatePosition();
    }

    private void owner_LocationChanged(object sender, System.EventArgs e)
    {
        UpdatePosition();
    }

    private void UpdatePosition()
    {
        Top = _owner.Top + 1;
        Left = _owner.Left + 8;
    }
}

As you notice one has to handle a lot of window behaviors like activity status and location changes yourself, which easily can get a bit messy.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top