This article shows the migration steps from MahApps 1.3.0 to 2.4.3 for BurageSnap, a screen capture tool. BurageSnap uses MahApps to realize its small footprint, as shown below.
Adapt Theme
I first changed the theme specifications as explained in the official document Migration to v2.0.
Old NewAdapt Style
Then I had to fix the following style settings. MetroWindow
in MahApps 2.x doesn't have the dynamic resource and the properties.
<Style x:Key="WindowStyle" TargetType="mah:MetroWindow">
...
<Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}"/>
<Setter Property="TitlebarHeight" Value="24"/>
<Setter Property="TitleCaps" Value="False"/>
<Setter Property="WindowMinButtonStyle" Value="{StaticResource WindowButtonStyle}"/>
<Setter Property="WindowCloseButtonStyle" Value="{StaticResource WindowButtonStyle}"/>
...
AccentColorBrush
The resource of the same brush can be referred as follows.
Window Title
TitlebarHeight
was just superseded by TitleBarHeight
. TitleCaps
was replaced by TitleCharacterCasing
but having a CharcterCasing type value. I modified these settings as follows.
<Setter Property="TitleBarHeight"Value="24">
<Setter Property="TitleCharacterCasing" Value="Normal"/>
Window Buttons
I used the style properties WindowMinButtonStyle
and WindowCloseButtonStyle
to make the minimize and close buttons small. But these were eliminated in MahApps 2.x.
Instead, WindowButtonCommands
inside MetroWindow
has the corresponding properties, LightMinButtonStyle
and LightCloseButtonStyle
in case of light themes. When defining a style inside another style, we can use Style.Resources
as follows.
I defined the above WindowButtonStyle
to make the button width narrow as follows, but the base style MetroBaseWindowButtonStyle
is missing in MahApps 2.x so I had to replace it with MahApps.Styles.Button.MetroWindow.Light
.
<Style x:Key="WindowButtonStyle" TargetType="Button" BasedOn="{StaticResource MetroBaseWindowButtonStyle}">
<Setter Property="Width" Value="26"/>
</Style>
Button Labels
There were other errors in the following ButtonStyle
to disable capitalization and boldness of the button labels in the default style. There aren't the MetroButton
style and the ButtonHelper
class in the 2.x.
<Style x:Key="ButtonStyle" TargetType="Button" BasedOn="{StaticResource MetroButton}">
<Setter Property="mah:ButtonHelper.PreserveTextCase" Value="True"/>
<Setter Property="FontWeight" Value="Normal"/>
</Style>
These replacements are MahApps.Styles.Button
and ControlsHelper
respectively. ControlsHelper
, however, have ContentCharacterCasing
not PreserveTextCase
. Those errors were fixed as follows.
Next Step
That's all of the migration. Next, I had to migrate Prism from 6.2 to 8.0. MahApps.Metro 2.x is incompatible with the older versions of Prism. Because XamlBehaviors.WPF, the 2.x depends on, conflicts with Windows.Interactivity, the older Prism depends on. I will show the migration steps in another article.
Updated on 2021-05-19: Correct some mistakes and mention other changes.