thoemmi / TinyLittleMvvm

A small MVVM library for WPF built on top of MahApps.Metro, supporting .NET Framework >= 4.7.2 and .NET Core >= 3
MIT License
131 stars 22 forks source link

Changes required to support MahApps.Metro 2.0+ and above #38

Closed jnewcomb closed 4 years ago

jnewcomb commented 4 years ago

Nice project, thanks for sharing. For those trying to figure out how to get going with the non-beta versions of MahApps a few handy pointers. It needs to be updated to work with the new Theme manager https://mahapps.com/docs/guides/migration-to-v2.0 https://mahapps.com/docs/themes/thememanager

.NET CORE 3.0 is marked EOL, so it's a good opportunity to update to 3.1 marked as LTS https://dotnet.microsoft.com/platform/support/policy/dotnet-core

This is what I did.. Hope this helps you out..

In TinyLittleMvvm.csprj

Updated to 3.1 (optional)

<TargetFramework>netcoreapp3.1</TargetFramework>

Updated packages to

<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.7" />
<PackageReference Include="MahApps.Metro" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.7" />

In DialogManager.cs, FlyoutManager.cs

Replace all occurrences

Uri("pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml")

With

Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.FlatButton.xaml")

In TinyLittleMvvmDemo.cs

Updated to 3.1 (optional)

<TargetFramework>netcoreapp3.1</TargetFramework>

Updated packages to

<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.7" />

In SampleFlyout.cs

Add the new theming:

using ControlzEx.Theming;

Replace these functions with:

        public SampleFlyoutViewModel() {
            this.AccentColors = ThemeManager.Current.Themes
                .GroupBy(x => x.ColorScheme)
                .OrderBy(a => a.Key)
                .Select(a => new AccentColorMenuData {
                    Name = a.Key,
                    ColorBrush = a.First().ShowcaseBrush
                })
                .ToList();
            var theme = ThemeManager.Current.DetectTheme(Application.Current);
            _currentAccentColor = AccentColors.Single(accent => accent.Name == theme.ColorScheme);

            OkCommand = new RelayCommand(OnOk, () => !HasErrors);
            CancelCommand = new RelayCommand(Close);
        }

        public AccentColorMenuData CurrentAccentColor {
            get { return _currentAccentColor; }
            set {
                if (_currentAccentColor != value) {
                    _currentAccentColor = value;
                    ThemeManager.Current.ChangeThemeColorScheme(Application.Current, value.Name);
                }
            }
        }
thoemmi commented 4 years ago

Thanks @jnewcomb. I've added your changes and published 2.0.0-unstable.44.

However, I've kept 3.1 for Microsoft.Extensions-packages as the lowest requirement.