• ContextMenu的自定义


    1.针对整个ContextMenu, 自定义一个Style,去掉竖分割线


          <Style x:Key="DataGridColumnsHeaderContextMenuStyle"  TargetType="{x:Type ContextMenu}">
                    <Setter Property="SnapsToDevicePixels" Value="True"/>
                    <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
                    <Setter Property="HasDropShadow" Value="True"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ContextMenu}">
                                <Border Uid="Border_93">
                                    <Border.Style>
                                        <Style TargetType="{x:Type Border}">
                                            <Setter Property="Tag" Value="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Tag, RelativeSource={RelativeSource Self}}" Value="True">
                                                    <Setter Property="Effect">
                                                        <Setter.Value>
                                                            <DropShadowEffect BlurRadius="4" Opacity="0.8" ShadowDepth="1"/>
                                                        </Setter.Value>
                                                    </Setter>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Border.Style>
                                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Uid="Border_50">
                                        <ScrollViewer CanContentScroll="True"  Uid="ScrollViewer_9"
                                Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Uid="ItemsPresenter_5"/>
                                        </ScrollViewer>
                                    </Border>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>


    2. 针对其中的ItemContainerStyle来写个MenuItem的control template

    <Style x:Key="MenuItemStyle1" TargetType="{x:Type MenuItem}"> <Setter Property="Template" Value="{DynamicResource MenuItemControlTemplate1}"/> <Setter Property="Margin" Value="0"></Setter> <Setter Property="Padding" Value="0"></Setter> </Style> <ControlTemplate x:Key="MenuItemControlTemplate1" TargetType="{x:Type MenuItem}"> <Grid x:Name="grid" SnapsToDevicePixels="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" > <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="0" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsHighlighted" Value="True"> <Setter Property="Background" TargetName="grid" Value="{DynamicResource Brush_PA_CSW_ListBoxItemDefaultHighlight}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="#FF9A9A9A"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>

    3. contextMenu使用上述style

     <ContextMenu x:Key="DataGridColumnsHeaderContextMenu" 
            ItemTemplate="{DynamicResource HeaderConfigItemTemplate}"  
            ItemContainerStyle="{DynamicResource MenuItemStyle1}"
                    Style="{DynamicResource DataGridColumnsHeaderContextMenuStyle}"
    />
  • 相关阅读:
    wepack性能优化-contenthash(缓存)
    webpack优化系列-oneOf
    webpack性能优化-source-map
    webpack性能优化-HMR
    vue__之路由懒加载
    vue__之ref的作用
    圆面积和球体积
    算法思想
    看完com本质论第一章
    windows消息机制
  • 原文地址:https://www.cnblogs.com/muzizongheng/p/3169444.html
Copyright © 2020-2023  润新知