WPFはWinFormsの後継のユーザインタフェースサブシステムです。しかし、.NET Framework 3.0の時代からあるので、UIが古臭いです。

そこで、このUIたちをどうにかできないかとGoogleを散策しているととあるライブラリを見つけました。ModernWpfです。

Windows10の見た目に合ったUIで個人的に気に入りました。しかし、Windows10の見た目というところで躓くことになるのですが…
あらすじ
プロジェクトに導入
NugetからModernWpfUIをインストール
NugetからModernWpfUIとModernWpfUI.MessageBoxをインストールしましょう。


そのあと、App.xamlをこのように変更します。
<Application x:Class="ModernWpfTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ModernWpfTest"
xmlns:ui="http://schemas.modernwpf.com/2019"
StartupUri="MainWindow.xaml">
<!-- xmlns:ui="http://schemas.modernwpf.com/2019"を追加 -->
<Application.Resources>
<!-- ここから -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemeResources />
<ui:XamlControlsResources />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
</ResourceDictionary>
<!-- ここまでをApplication.Resourcesに追加 -->
</Application.Resources>
</Application>
最後に、適用したいウィンドウをこのようにします。
<Window x:Class="ModernWpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ModernWpfTest"
mc:Ignorable="d"
xmlns:ui="http://schemas.modernwpf.com/2019"
ui:WindowHelper.UseModernWindowStyle="True"
Title="MainWindow" Height="450" Width="800">
<!-- xmlns:ui="http://schemas.modernwpf.com/2019"
ui:WindowHelper.UseModernWindowStyle="True"を追加 -->
普通、ここで作業は終了なのですが、実行しようとしてみるとエラーが出ます。


エラーを見てみると、WinRTの組み込み…などと書かれています。何が原因なのか当初は理解できませんでした。
エラーの解決方法
ここで、最初に言ったWindows10の見た目が出てきます。Windows10の見た目なら、Windows10より昔ののOSでしか動くはずがありません。
解決方法は単純です。プロジェクトのプロパティからターゲットOSバージョンとサポートされているOSのバージョンを変更すればOKです。


これでビルドしてみると、正常に動作します。

これで導入をあきらめていた人々の助けになれば幸いです。
最後までご覧いただきありがとうございました。
コメント