c# - 如何在 XAML 工具包 (WPF) 中的 Material Design 中激活汉堡菜单时禁用灰色覆盖

标签 c# wpf xaml

这是来自示例应用的叠加层图片: enter image description here

这是 Material Design In XAML Toolkit 的 git 页面(您可以在此处下载演示项目):Toolkit:https://github.com/ButchersBoy/MaterialDesignInXamlToolkit

这可能是 Material Design In XAML Toolkit 库中某处的属性,我想问问是否有人知道如何设置它(或者是否甚至可以关闭覆盖)。

<Window x:Class="MaterialDesignColors.WpfExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        
        xmlns:wpfExample="clr-namespace:MaterialDesignColors.WpfExample"
        xmlns:domain="clr-namespace:MaterialDesignColors.WpfExample.Domain"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        xmlns:domain1="clr-namespace:MaterialDesignDemo.Domain"
        xmlns:materialDesignDemo="clr-namespace:MaterialDesignDemo"
        Title="Material Design in XAML" Height="800" Width="1100"
        TextElement.Foreground="{DynamicResource MaterialDesignBody}"
        TextElement.FontWeight="Regular"
        TextElement.FontSize="13"
        TextOptions.TextFormattingMode="Ideal" 
        TextOptions.TextRenderingMode="Auto"        
        Background="{DynamicResource MaterialDesignPaper}"
        FontFamily="{StaticResource MaterialDesignFont}" Icon="favicon.ico">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <!-- data template used for the dialogs example, defines a View for a ViewModel of type DateTime  -->
            <DataTemplate DataType="{x:Type system:DateTime}">
                <StackPanel Margin="16">
                    <TextBlock>England win the World Cup:</TextBlock>
                    <TextBlock Margin="0 8 0 0" Text="{Binding }" />
                    <TextBlock Margin="0 8 0 0" >You will never see that again.</TextBlock>
                    <Button  Margin="0 8 0 0" IsDefault="True" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignFlatButton}">AWESOME</Button>
                </StackPanel>
            </DataTemplate>
        </ResourceDictionary>
    </Window.Resources>

    <materialDesign:DialogHost Identifier="RootDialog">
        <materialDesign:DrawerHost IsLeftDrawerOpen="{Binding ElementName=MenuToggleButton, Path=IsChecked}">
            <materialDesign:DrawerHost.LeftDrawerContent>
                <DockPanel MinWidth="212">
                    <ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" 
                                  DockPanel.Dock="Top"
                                  HorizontalAlignment="Right" Margin="16"
                                  IsChecked="{Binding ElementName=MenuToggleButton, Path=IsChecked, Mode=TwoWay}" />                    
                    <ListBox x:Name="DemoItemsListBox" Margin="0 16 0 16" SelectedIndex="0"                         
                             PreviewMouseLeftButtonUp="UIElement_OnPreviewMouseLeftButtonUp">
                        <ListBox.ItemTemplate>
                            <DataTemplate DataType="domain:DemoItem">
                                <TextBlock Text="{Binding Name}" Margin="32 0 32 0" />
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <domain:DemoItem Name="Home">

...

                        <domain:DemoItem Name="Shadows">
                            <domain:DemoItem.Content>
                                <wpfExample:Shadows />
                            </domain:DemoItem.Content>
                        </domain:DemoItem>
                    </ListBox>
                </DockPanel>
            </materialDesign:DrawerHost.LeftDrawerContent>
            <DockPanel>
                <materialDesign:ColorZone Padding="16" materialDesign:ShadowAssist.ShadowDepth="Depth2"
                                          Mode="PrimaryMid" DockPanel.Dock="Top">
                    <DockPanel>
                        <ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="False"
                                      x:Name="MenuToggleButton"/>
                        <materialDesign:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
                            <StackPanel>
                                <Button Content="Hello World" Click="MenuPopupButton_OnClick"/>
                                <Button Content="Nice Popup" Click="MenuPopupButton_OnClick"/>
                                <Button Content="Goodbye" Click="MenuPopupButton_OnClick"/>                                
                            </StackPanel>
                        </materialDesign:PopupBox>
                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22">Material Design In XAML Toolkit</TextBlock>
                    </DockPanel>
                </materialDesign:ColorZone>
                <ContentControl Margin="16" Content="{Binding ElementName=DemoItemsListBox, Path=SelectedItem.Content}" />                
            </DockPanel>
        </materialDesign:DrawerHost>
    </materialDesign:DialogHost>
</Window>

最佳答案

黑色阴影是由于 Generic.xaml 中定义的网格造成的:

<Grid x:Name="PART_ContentCover" Background="{x:Null}" Opacity="0" 
      IsHitTestVisible="False" Focusable="False"  />

在绘制抽屉时将不透明度设置为 0.56 的动画。不幸的是,此网格不属于任何模板,因此您无法在客户端 xaml 中更改它。

另一种选择是更改也在 Generic.xaml 中定义的阴影的黑色画笔:

<SolidColorBrush x:Key="BlackBackground" Color="Black" />

但这也是我不知道如何从客户端 xaml 更改的东西,所以在拥有更多 WPF skillz 的人提供更好的选择之前,唯一的建议是简单地重新编译源代码并将黑色笔刷更改为:

<SolidColorBrush x:Key="BlackBackground" Color="#00000000" />

或者,您可以使用另一个演示中显示的弹出控件,它没有深色阴影功能,但除此之外是相同的。

更新:我找到了解决这个问题的方法。您可以像这样子类化 DrawerHost:

public class DrawerHostEx : DrawerHost
{
    public DrawerHostEx()
    {
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        var grid = GetTemplateChild(TemplateContentCoverPartName) as System.Windows.Controls.Grid;
        grid.Visibility = System.Windows.Visibility.Collapsed;
    }
}

然后您只需在 XAML 中将 DrawerHost 替换为 DrawerHostEx。

关于c# - 如何在 XAML 工具包 (WPF) 中的 Material Design 中激活汉堡菜单时禁用灰色覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38572855/

相关文章:

c# - 将 D3DImage 转换为字节数组

c# - 使用 try catch 语句仅允许用户在 Button Click 事件上将整数输入到文本框中

wpf - 在列表框中填充网格宽度

c# - 如何在 wpf datagrid 中获取所选单元格的行标题值?

c# - richtextbox 到字符串

c# - 在 TableLayoutPanel 中交换控件位置

c# - 在 Windows 服务中从 OnStart 立即触发 timer_elapsed

c# - 将 2 个字节转换为数字

wpf - 移动焦点以响应 XAML 中的键盘事件

C# 带有空检查的重复代码