如何设置MenuBar的前台属性(UWP,XML)

时间:2019-06-19 15:17:38

标签: uwp-xaml

此问题是MenuBar独有的。我可以设置background属性,但是设置其他属性不会更改UI。

(App.xml)

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
        </ResourceDictionary.MergedDictionaries>

        <!--#region Brushes -->

        <!-- Background Brushes -->
        <SolidColorBrush x:Key="Main_ColourBrush" Color="#DC143C"/>
        <SolidColorBrush x:Key="Background1_ColourBrush" Color="#1E1E1E"/>
        <SolidColorBrush x:Key="Background2_ColourBrush" Color="#222"/>
        <SolidColorBrush x:Key="BackgroundSearchBox_ColourBrush" Color="#B2B2B2"/>

        <!-- Foreground Brushes -->
        <SolidColorBrush x:Key="ForegroundSearchBox_ColourBrush" Color="#4C4C4C"/>
        <SolidColorBrush x:Key="ForegroundTextBrush_ColourBrush" Color="#DBDBDB"/>
        <!--#endregion-->

        <!-- Menus -->
        <Style x:Key="MainMenu_MenuBar_Style" TargetType="muxc:MenuBar">
            <Setter Property="Foreground" Value="{StaticResource ForegroundTextBrush_ColourBrush}"/>
            <Setter Property="Background" Value="{StaticResource BackgroundSearchBox_ColourBrush}"/>
            <Setter Property="FontFamily" Value="Calibri"/>
            <Setter Property="FontSize" Value="18"/>
            <Setter Property="FontWeight" Value="Bold"/>
        </Style>

        <!-- Text Block -->
        <Style x:Key="Title_TextBlock_Style" TargetType="TextBlock">
            <Setter Property="Foreground" Value="{StaticResource ForegroundTextBrush_ColourBrush}"/>
            <Setter Property="FontFamily" Value="Calibri"/>
            <Setter Property="FontSize" Value="20"/>
            <Setter Property="FontWeight" Value="Bold"/>
        </Style> ...
    </ResourceDictionary>
</Application.Resources>

除MenuBar代码外,一切正常,减去background属性。

<muxc:MenuBar Grid.Column="0" Grid.Row="0"
                  Style="{StaticResource MainMenu_MenuBar_Style}">

我尝试在标记中创建样式以产生相同的结果

1 个答案:

答案 0 :(得分:0)

不是直接解决方案,但是对于我来说,解决方法是设置

<MenuBar RequestedTheme="Dark">