带模板的功能区导致透明背景

时间:2014-02-26 00:36:37

标签: c# wpf ribboncontrolslibrary

我终于设法模拟我的功能区并使用数据绑定添加所有内容。 然而,我有一个非常丑陋的“dropdownmenu”背景已变得透明(尽管阴影仍然存在!)

enter image description here

首先是什么叫“dropdownmenu”?最后我应该编辑哪些属性以便为这个“dropdownmenu”提供适当的背景?

最诚挚的问候!

1 个答案:

答案 0 :(得分:0)

该菜单是折叠组的下拉菜单。折叠组是RibbonToggleButton + Popup的组合。在模板中,Popup看起来像这样:

<Popup x:Name="PART_Popup"
                    AllowsTransparency="true"
                    Placement="Bottom"                               
                    PlacementTarget="{Binding ElementName=PART_ToggleButton}"
                    IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
                    Focusable="false"
                    PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}">
    <classic:SystemDropShadowChrome Name="Shdw" 
                                Color="Transparent" 
                                SnapsToDevicePixels="true" 
                                CornerRadius="2" 
                                Focusable="True" 
                                FocusVisualStyle="{x:Null}"
                                controls:KeyTipService.IsKeyTipScope="True"

                                RenderOptions.ClearTypeHint="Enabled"

                                >
        <Grid Name="PopupGrid" Height="{TemplateBinding ActualHeight}" Margin="0,1.5,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" MinHeight="16" />
            </Grid.RowDefinitions>
            <Border Name="PopupBorder" Grid.RowSpan="2"
                Background="{TemplateBinding Background}"
                BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Ribbon.BorderBrush}"
                BorderThickness="1"/>
            <Border Name="PART_HotBackground"
                Background="{TemplateBinding MouseOverBackground}"
                BorderBrush="{TemplateBinding MouseOverBorderBrush}"
                Opacity="0"
                Grid.RowSpan="2"
                CornerRadius="2"
                BorderThickness="1"
                SnapsToDevicePixels="True"/>
            <Border Margin="2,3.5,2,0" Padding="3,0,3,0" x:Name="PART_RibbonControlsHostBorder">
                <Grid>
                    <ItemsPresenter Name="ItemsPresenter" KeyboardNavigation.TabNavigation="Cycle"
                                        KeyboardNavigation.DirectionalNavigation="Cycle"
                                        SnapsToDevicePixels="True"
                                        Grid.IsSharedSizeScope="true"/>
                    <ContentControl Name="TemplateContentControl" Visibility="Collapsed" Focusable="False"/>
                </Grid>
            </Border>
            <Grid Margin="2,0,2,1" Grid.Row="1">
                <ContentPresenter Name="PART_Header"
                                TextElement.Foreground="{StaticResource &#203;}"
                                ContentSource="Header"
                                Margin="2,0,2,0"
                                MaxHeight="15"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"/>
            </Grid>
        </Grid>
    </classic:SystemDropShadowChrome>
</Popup>

如您所见,Background继承自RibbonGroup。 所以,你有几个变种来解决它:

  1. Background设置不透明的RibbonGroup媒体资源
  2. Retemplate