I have a simple test application that shows a simple Mahapps MetroWindow with an attached Behaviour. The problem is when attaching the Behaviour the outer border of the Mahapps MetroWindow is drawn.

<controls:MetroWindow x:Class="Desktop.Shell.Modern.ShellView"
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:cal="http://www.caliburnproject.org"
xmlns:modern="clr-namespace:Desktop.Shell.Modern"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
Height="350"
Width="525"
ResizeMode="CanResizeWithGrip"
WindowTransitionsEnabled="True"
ShowIconOnTitleBar="False"
TitleCaps="False"
GlowBrush="{DynamicResource WindowTitleColorBrush}" >
<i:Interaction.Behaviors>
<modern:SomeBehavior SomeKey="{Binding Key}" />
</i:Interaction.Behaviors>
<ContentControl cal:View.Model="{Binding ActiveItem}" />
</controls:MetroWindow>
When removing the Behaviour everything looks as expected:

... but the Behaviour itself did nothing (yet). Here is the code of the SomeBehaviour class:
public sealed class SomeBehavior : Behavior<Window>
{
public static readonly DependencyProperty SomeKeyProperty =
DependencyProperty.Register(
"SomeKey",
typeof(Key),
typeof(SomeBehavior),
new PropertyMetadata(default(Key)));
public Key SomeKey
{
get
{
return (Key)this.GetValue(SomeKeyProperty);
}
set
{
this.SetValue(SomeKeyProperty, value);
}
}
protected override void OnAttached()
{
base.OnAttached();
}
protected override void OnDetaching()
{
base.OnDetaching();
}
}
Am I doing something wrong? Should I attach the Behaviour in a different way than attaching them to "normal" Windows?
That's because Mahapps.Metro sets its required behaviours in the window style, see MetroWindow.xaml.
If you want to attach additional behaviors, you have to copy these behaviours to your window, e.g.
<controls:MetroWindow x:Class="Desktop.Shell.Modern.ShellView"
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:cal="http://www.caliburnproject.org"
xmlns:modern="clr-namespace:Desktop.Shell.Modern"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:Behaviours="http://metro.mahapps.com/winfx/xaml/shared"
Height="350"
Width="525"
ResizeMode="CanResizeWithGrip"
WindowTransitionsEnabled="True"
ShowIconOnTitleBar="False"
TitleCaps="False"
GlowBrush="{DynamicResource WindowTitleColorBrush}" >
<i:Interaction.Behaviors>
<modern:SomeBehavior SomeKey="{Binding Key}" />
<Behaviours:BorderlessWindowBehavior />
<Behaviours:WindowsSettingBehaviour />
<Behaviours:GlowWindowBehavior />
</i:Interaction.Behaviors>
<ContentControl cal:View.Model="{Binding ActiveItem}" />
</controls:MetroWindow>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With