惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Palo Alto Networks Blog
S
Security Affairs
T
Tor Project blog
T
Threatpost
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
A
Arctic Wolf
K
Kaspersky official blog
O
OpenAI News
Spread Privacy
Spread Privacy
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
Simon Willison's Weblog
Simon Willison's Weblog
雷峰网
雷峰网
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
量子位
博客园_首页
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
V2EX - 技术
V2EX - 技术
S
Schneier on Security
博客园 - 叶小钗
Attack and Defense Labs
Attack and Defense Labs
AI
AI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 【当耐特】
Jina AI
Jina AI
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
D
Darknet – Hacking Tools, Hacker News & Cyber Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
H
Hacker News: Front Page
The Last Watchdog
The Last Watchdog
V
V2EX
S
SegmentFault 最新的问题
V
Visual Studio Blog
PCI Perspectives
PCI Perspectives
Microsoft Security Blog
Microsoft Security Blog

博客园 - 昨夜飘风

WPF 通过共享内存播放视频 C# 模拟网页拖拽 .net4.0中wpf单例启动 Oracle 开发经验 WPF跑马灯效果 android私有文件夹的访问 [转]C#内存操作 C#串口发送接受数据 C# 制作外挂常用的API silverlight 动画 性能优化 SilverLight 动画缓冲(Animation Easing) - 昨夜飘风 体面地处理程序的未捕获异常 C# 访问USB(HID)设备 收藏一个地址(居然说我标题已经存在) 收藏一个地址 (2009-06-24) SqlCommandBuilder使用的注意事项 助睡眠音乐 (2009-06-22) 班德瑞官方试听网站 (2009-06-18)今日收获 工厂方法 (2009-06-17)今日收获-只读列隐藏-win2003 dll文件下载
wpf 自定义ContextMenu样式,可以调节ContextMenu的宽度
昨夜飘风 · 2012-06-20 · via 博客园 - 昨夜飘风

 之前在网上找的ContextMenu的样式,都不可以把宽度设置到142以下,否则文字就被隐藏了一部分,所以重新改了下样式,下面是xaml代码,注意动画的最终的高宽和MenuItem的高宽,改下看效果就知道实现自己的效果要改那些东西了.

<Style TargetType="{x:Type ContextMenu}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ContextMenu}">
                        <Border x:Name="Border" CornerRadius="4" Background="#A5181818"  BorderThickness="2">
                            <Border.BorderBrush>
                                <SolidColorBrush Color="#BABABA" />
                            </Border.BorderBrush>
                            <ItemsPresenter/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsMouseOver" Value="True"/>
                                </MultiTrigger.Conditions>
                                <MultiTrigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"  Storyboard.TargetProperty="(FrameworkElement.Width)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.0020000" Value="0"/>
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.3450000" Value="95"/>
                                            </DoubleAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00"  Storyboard.TargetProperty="(FrameworkElement.Height)">
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.0020000" Value="0"/>
                                                <SplineDoubleKeyFrame KeyTime="00:00:00.3450000" Value="54"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </MultiTrigger.EnterActions>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="{x:Type MenuItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type MenuItem}">
                        <Border Margin="1" MinWidth="80" CornerRadius="5">
                            <Border.Background>
                                <SolidColorBrush x:Name="MyAnimatedBrushBackground" Color="Transparent" />
                            </Border.Background>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text=" "/>
                                <ContentPresenter ContentSource="Icon" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                <TextBlock Text="   "/>  
                                <ContentPresenter ContentSource="Header" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </StackPanel>
                        </Border>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsMouseOver" Value="True"/>
                                </MultiTrigger.Conditions>
                                <MultiTrigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MyAnimatedBrushBackground" Storyboard.TargetProperty="Color">
                                                <LinearColorKeyFrame Value="Transparent" KeyTime="00:00:00.0020000" />
                                                <LinearColorKeyFrame Value="#7E9C9C9C" KeyTime="00:00:00.0320000" />
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </MultiTrigger.EnterActions>
                                <MultiTrigger.ExitActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MyAnimatedBrushBackground" Storyboard.TargetProperty="Color">
                                                <LinearColorKeyFrame Value="#7E9C9C9C" KeyTime="00:00:00.0020000" />
                                                <LinearColorKeyFrame Value="Transparent" KeyTime="00:00:00.0320000" />
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </MultiTrigger.ExitActions>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

<ContextMenu Cursor="Hand" StaysOpen="true">
                <MenuItem Name="menuLook" Foreground="Black" Height="25">
                    <MenuItem.Icon>
                        <Image  Width="21" Height="21" Source="search.png"></Image>
                    </MenuItem.Icon>
                    <MenuItem.Header>
                        <TextBlock Text="查看图片" Height="21"/>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem Name="menuEdit" Foreground="Black" Height="25">
                    <MenuItem.Icon>
                        <Image Width="21" Height="21" Source="tools.png"></Image>
                    </MenuItem.Icon>
                    <MenuItem.Header>
                        <TextBlock Text="图片增强" Height="21"/>
                    </MenuItem.Header>
                </MenuItem>

            </ContextMenu>