如何使用 MahApps 在所有应用 windows 上设置 windows 10 种标题栏按钮样式

How to set windows 10 title bar button style on all app windows with MahApps

我是 WPF 的新手,我正在使用 MahApps。我想在我的应用程序中的所有 windows 上设置 Windows 10 个样式的标题栏按钮。我可以通过添加

为每个 window 单独执行此操作
<ma:MetroWindow.WindowButtonCommands>
    <ma:WindowButtonCommands Style="{DynamicResource MahApps.Styles.WindowButtonCommands.Win10}" />
</ma:MetroWindow.WindowButtonCommands>

每个 window xaml。但是,我想将其设置为 App.xaml 中的样式,这样我就不必在每个 window 中都复制它。我试过了

<Application.Resources>
    <ResourceDictionary>
        <Style x:Key="WindowStyle" TargetType="{x:Type ma:MetroWindow}">
            <Setter Property="WindowButtonCommands">
                <Setter.Value>
                    <ma:WindowButtonCommands Style="{DynamicResource MahApps.Styles.WindowButtonCommands.Win10}" />
                </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>
</Application.Resources>

但它只适用于第一个 window。随后 windows 打开崩溃,错误 "Specified element is already the logical child of another element. Disconnect it first." 显然,只有一个 WindowButtonCommands 实例被实例化,只能分配给一个 window。我不确定从这里到哪里去。

尝试将 WindowButtonCommands 元素定义为单独的非共享资源:

<Application.Resources>
    <ResourceDictionary>
        <ma:WindowButtonCommands x:Key="commands" x:Shared="False" Style="{DynamicResource MahApps.Styles.WindowButtonCommands.Win10}" />
        <Style x:Key="WindowStyle" TargetType="{x:Type ma:MetroWindow}">
            <Setter Property="WindowButtonCommands" Value="{StaticResource commands}" />
        </Style>
    </ResourceDictionary>
</Application.Resources>