After adding <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Flyout.xaml"/> getting error ArgumentNullException: Value cannot be null. Set property 'System.Windows.Setter.Property' threw an exception. from InitializeComponent();
After removing MaterialDesignTheme.MahApps.Flyout.xaml line from App.xaml it works fine...
In design mode there is error The given key was not present in the dictionary. App.xaml apparently caused by <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Flyout.xaml"/>
Demo: https://github.com/pavka1799/MDesignMahAppsFlyoutCompatIssue.git
MaterialDesignThemes 3.0.0
MahApps.Metro 2.0.0-alpha0660
MaterialDesignThemes.MahApps 0.1.1-ci870
@pavka1799
the ControlHelper.HeaderFontSize has Removed In MahApps.Metro 2.0.0-alpha0660 , replace ControlHelper with HeaderedControlHelper can solve your problem
MaterialDesignTheme.MahApps.Flyout.xaml
`
xmlns:mahApps="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mahShared="http://metro.mahapps.com/winfx/xaml/shared"
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf">
<DataTemplate x:Key="HeaderTemplate" x:Shared="False">
<wpf:ColorZone x:Name="PART_ColorZone"
wpf:ShadowAssist.ShadowDepth="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mahApps:FlyoutAssist.HeaderShadowDepth)}"
Mode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mahApps:FlyoutAssist.HeaderColorMode)}">
<DockPanel x:Name="dpHeader"
Margin="{Binding Path=(mah:HeaderedControlHelper.HeaderMargin), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:Flyout}}, Mode=OneWay}"
VerticalAlignment="Center" LastChildFill="True">
<Button x:Name="PART_BackButton" Width="34" Height="34" Margin="2,4,2,2" VerticalAlignment="Bottom"
DockPanel.Dock="Left"
Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:Flyout}}, Path=Foreground}"
IsCancel="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:Flyout}}, Path=CloseButtonIsCancel}"
Style="{DynamicResource MaterialDesignToolButton}"
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:Flyout}}, Path=CloseButtonVisibility}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<mahShared:CloseFlyoutAction Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:Flyout}}, Path=CloseCommand, Mode=OneWay}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:Flyout}}, Path=CloseCommandParameter, Mode=OneWay}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<wpf:PackIcon Width="{DynamicResource MahApps.Sizes.Font.FlyoutHeader}"
Height="{DynamicResource MahApps.Sizes.Font.FlyoutHeader}"
FlowDirection="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:Flyout}}, Path=FlowDirection}"
Kind="ChevronRight" />
</Button>
<ContentControl x:Name="PART_BackHeaderText" Margin="15,0,0,0" VerticalAlignment="Center"
Content="{Binding}"
Focusable="False" IsTabStop="False"
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type mah:Flyout}}, Path=TitleVisibility}" />
</DockPanel>
</wpf:ColorZone>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Position, RelativeSource={RelativeSource AncestorType={x:Type mah:Flyout}}}" Value="Left">
<Setter TargetName="PART_BackHeaderText" Property="Margin" Value="0,0,15,0" />
<Setter TargetName="PART_BackHeaderText" Property="HorizontalAlignment" Value="Right" />
<Setter TargetName="PART_BackButton" Property="DockPanel.Dock" Value="Right" />
<Setter TargetName="PART_BackButton" Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="-1" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Position, RelativeSource={RelativeSource AncestorType={x:Type mah:Flyout}}}" Value="Top">
<Setter TargetName="PART_ColorZone" Property="VerticalAlignment" Value="Stretch" />
<Setter TargetName="PART_BackButton" Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="-90" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Position, RelativeSource={RelativeSource AncestorType={x:Type mah:Flyout}}}" Value="Bottom">
<Setter TargetName="PART_ColorZone" Property="VerticalAlignment" Value="Stretch" />
<Setter TargetName="PART_BackButton" Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="90" />
</Setter.Value>
</Setter>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<ControlTemplate x:Key="FlyoutTemplate" TargetType="{x:Type mah:Flyout}">
<Grid x:Name="PART_Root" Background="{TemplateBinding Background}">
<Grid.RenderTransform>
<TranslateTransform />
</Grid.RenderTransform>
<AdornerDecorator x:Name="PART_Border" CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border Background="{TemplateBinding Background}" Effect="{DynamicResource MaterialDesignShadowDepth5}" />
</AdornerDecorator>
<AdornerDecorator>
<DockPanel FocusVisualStyle="{x:Null}" Focusable="False">
<mah:MetroThumbContentControl x:Name="PART_Header"
Content="{TemplateBinding Header}"
ContentCharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mah:ControlsHelper.ContentCharacterCasing)}"
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
DockPanel.Dock="Top"
FontSize="{TemplateBinding mah:HeaderedControlHelper.HeaderFontSize}"
FontStretch="{TemplateBinding mah:HeaderedControlHelper.HeaderFontStretch}"
FontWeight="{TemplateBinding mah:HeaderedControlHelper.HeaderFontWeight}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<ContentPresenter x:Name="PART_Content" ContentSource="Content" DockPanel.Dock="Bottom" />
</DockPanel>
</AdornerDecorator>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Default" />
<VisualState x:Name="Hide">
<Storyboard x:Name="HideStoryboard">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
<SplineDoubleKeyFrame x:Name="hideFrame" KeySpline="0.25,1,0.05,1" KeyTime="00:00:00.750" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)">
<SplineDoubleKeyFrame x:Name="hideFrameY" KeySpline="0.25,1,0.05,1" KeyTime="00:00:00.750" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame x:Name="fadeOutFrame" KeySpline="0.25,1,0.05,1" KeyTime="00:00:00.750" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Border" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeySpline="0.25,1,0.05,1" KeyTime="00:00:00.750" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Show">
<Storyboard x:Name="ShowStoryboard">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
<SplineDoubleKeyFrame x:Name="showFrame" KeySpline="0.25,1,0.05,1" KeyTime="00:00:00.750" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)">
<SplineDoubleKeyFrame x:Name="showFrameY" KeySpline="0.25,1,0.05,1" KeyTime="00:00:00.750" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeySpline="0.25,1,0.05,1" KeyTime="00:00:00.750" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="HideDirect">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="0" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)">
<SplineDoubleKeyFrame KeyTime="0" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="0" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ShowDirect">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="0" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)">
<SplineDoubleKeyFrame KeyTime="0" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PART_Root" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="0" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Position" Value="Top">
<Setter TargetName="PART_Content" Property="DockPanel.Dock" Value="Right" />
<Setter TargetName="PART_Header" Property="DockPanel.Dock" Value="Left" />
</Trigger>
<Trigger Property="Position" Value="Bottom">
<Setter TargetName="PART_Content" Property="DockPanel.Dock" Value="Right" />
<Setter TargetName="PART_Header" Property="DockPanel.Dock" Value="Left" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="CloseButtonVisibility" Value="Collapsed" />
<Condition Property="TitleVisibility" Value="Collapsed" />
</MultiTrigger.Conditions>
<Setter TargetName="PART_Header" Property="Visibility" Value="Collapsed" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="CloseButtonVisibility" Value="Hidden" />
<Condition Property="TitleVisibility" Value="Hidden" />
</MultiTrigger.Conditions>
<Setter TargetName="PART_Header" Property="Visibility" Value="Collapsed" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="{x:Type mah:Flyout}">
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}" />
<Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="mah:HeaderedControlHelper.HeaderFontSize" Value="{DynamicResource MahApps.Sizes.Font.FlyoutHeader}" />
<Setter Property="mah:HeaderedControlHelper.HeaderMargin" Value="10" />
<Setter Property="HeaderTemplate" Value="{StaticResource HeaderTemplate}" />
<Setter Property="KeyboardNavigation.ControlTabNavigation" Value="Cycle" />
<Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Cycle" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="Cycle" />
<Setter Property="Template" Value="{StaticResource FlyoutTemplate}" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Visibility" Value="Hidden" />
<Setter Property="mahApps:FlyoutAssist.HeaderColorMode" Value="PrimaryMid" />
<Setter Property="mahApps:FlyoutAssist.HeaderShadowDepth" Value="Depth2" />
<Style.Triggers>
<Trigger Property="Position" Value="Right">
<Setter Property="mah:HeaderedControlHelper.HeaderMargin" Value="10 25 10 10" />
</Trigger>
<Trigger Property="Position" Value="Left">
<Setter Property="mah:HeaderedControlHelper.HeaderMargin" Value="10 25 10 10" />
</Trigger>
<Trigger Property="TitleVisibility" Value="Collapsed">
<Setter Property="mahApps:FlyoutAssist.HeaderColorMode" Value="Standard" />
<Setter Property="mahApps:FlyoutAssist.HeaderShadowDepth" Value="Depth0" />
</Trigger>
<Trigger Property="TitleVisibility" Value="Hidden">
<Setter Property="mahApps:FlyoutAssist.HeaderColorMode" Value="Standard" />
<Setter Property="mahApps:FlyoutAssist.HeaderShadowDepth" Value="Depth0" />
</Trigger>
</Style.Triggers>
</Style>
`
@duanzlin - thanks a lot for explaining the reason of the issue!
If I got you right, the fix must be done to MaterialDesignTheme.MahApps.Flyout.xaml file. Does it mean I need to branch the project? Or should it somehow be fixed inside MaterialDesignTheme.MahApps project itself?
Thanks again!
Most helpful comment
@pavka1799
the ControlHelper.HeaderFontSize has Removed In MahApps.Metro 2.0.0-alpha0660 , replace ControlHelper with HeaderedControlHelper can solve your problem
MaterialDesignTheme.MahApps.Flyout.xaml
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
`
xmlns:mahApps="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mahShared="http://metro.mahapps.com/winfx/xaml/shared"
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf">
`