none
WPF如何设置半透明菜单 RRS feed

答案

全部回复

  •      WPF中ContextMenu弹出菜单可以设置成半透明,但它的二级菜单为什么设置不了?

          http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/thread/99909e4b-5d22-4cfb-a725-a88ed922a692
    2011年6月20日 3:01
  • 下载我的例子看下吧,修改MenuItem的样式可以做到:

     

    http://cid-51b2fdd068799d15.office.live.com/self.aspx/.Public/Samples%5E_2011/20110620%5E_TransparentContextMenu.zip

     

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年6月20日 6:47
    版主
  • 我跳进来说两句,你参考Bob给的例子,然后可以将Opacity属性进行绑定,这样比写死的数值会好点:

    <!-- Á¨®? MenuItem Content ¨´º?-->

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}" TargetType="{x:Type ContentControl}">

        <Border BorderBrush="#FF959595" BorderThickness="1" Background="White" Opacity="{Binding Path=Opacity, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}">

        <Grid>

            <Rectangle Fill="#F1F1F1" HorizontalAlignment="Left" Margin="2" RadiusY="2" RadiusX="2" Width="28"/>

            <Rectangle Fill="#E2E3E3" HorizontalAlignment="Left" Margin="30,2,0,2" Width="1"/>

            <Rectangle Fill="White" HorizontalAlignment="Left" Margin="31,2,0,2" Width="1"/>

            <ContentPresenter Grid.ColumnSpan="2" Margin="1,0"/>

        </Grid>

        </Border>

    </ControlTemplate>

    绑定部分你可以随便写。

    2)在打开半透明的MenuItem的时候,在两个MenuItem重叠的部分会出现不透明的现象, 你需要改变Popup的“HorizontalOffset” 属性,比如:

      <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false" HorizontalOffset="3.5" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right" VerticalOffset="-3">

    针对子级MenuItem的。

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年6月20日 10:16
    版主