Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MahApps.Metro's borderlesswindowbehavior does not work with stickywindows. #2820

Closed
RyadaProductions opened this issue Jan 27, 2017 · 0 comments
Labels
Milestone

Comments

@RyadaProductions
Copy link

RyadaProductions commented Jan 27, 2017

What steps will reproduce this issue?

StickyWindow library does not work in combination with MahApps.Metro custom border when you are dragging the form, resizing the form works like it should, Disabling BorderlessWindowBehavior makes it work but only when dragging the normal windows border, MahApps.Metro doesn't seem to raise the events Stickywindow needs when dragging.
Library can be found here:
http://programminghacks.net/2009/10/19/download-snapping-sticky-magnetic-windows-for-wpf/

XAML:

<controls:MetroWindow x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:Behaviours="http://metro.mahapps.com/winfx/xaml/shared"  
        xmlns:local="clr-namespace:MainProgram"
        Title="MainWindow" Height="212.148" Width="267.046" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
    <i:Interaction.Behaviors>
        <local:StickyWindowBehavior />
        <!--BorderlessWindowBehavior breaks the StickyWindowBehavior-->
        <Behaviours:BorderlessWindowBehavior />
        <Behaviours:WindowsSettingBehaviour />
        <Behaviours:GlowWindowBehavior />
    </i:Interaction.Behaviors>
    <Grid>
    </Grid>
</controls:MetroWindow>

StickyWindowBehavior.cs:

using Blue.Windows;
using System.Windows;
using System.Windows.Interactivity;

namespace MainProgram {
  public class StickyWindowBehavior : Behavior<Window> {
    private StickyWindow stickWindow;

    protected override void OnAttached() {
      base.OnAttached();
      AssociatedObject.Loaded += delegate {
        stickWindow = new StickyWindow(AssociatedObject) { StickToScreen = true, StickToOther = true, StickOnResize = true, StickOnMove = true };
      };
    }

    protected override void OnDetaching() {
      base.OnDetaching();
      if (stickWindow != null)
        stickWindow.ReleaseHandle();
    }
  }
}

Expected outcome

The windows that have the StickyWindowBehavior should be sticky when the borders are close to eachother while dragging the window around.

Environment

  • MahApps.Metro v1.4.1
  • Windows 7/8/8.1/10
  • Visual Studio 2015
  • .NET Framework 4.6.1
@punker76 punker76 added the Bug label Dec 5, 2018
@punker76 punker76 added this to the 2.0.0 milestone Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants