WPF初探--弹出菜单

来源:互联网 时间:1970-01-01

在XAML中,指定控件的ContentMenu属性下,添加一个具体的标签即可,在运行时,点击鼠标右键,就会弹出这个菜单。

以TreeView为例

<TreeView Name="treeView">

            <TreeViewItem Header="演示弹出菜单"/>           
            <!--渐变背景-->
            <TreeView.Background>
                <LinearGradientBrush EndPoint="0.63,0.483" StartPoint="-0.295,0.483">
                    <GradientStop Color="#FF8A8383" Offset="0"/>
                    <GradientStop Color="#FFFFFFFF" Offset="1"/>
                </LinearGradientBrush>
            </TreeView.Background>

            <!-- 此处就实现了一个弹出菜单的制作-->
            <TreeView.ContextMenu>
                <ContextMenu Name="popMenu" StaysOpen="True">
                    <MenuItem Name="refleshTree" Header="刷新" Click="refleshTree_Click"></MenuItem>
                </ContextMenu>
            </TreeView.ContextMenu>
        </TreeView>

本文来自JarvisChu的博客,原文地址:http://blog.csdn.net/JarvisChu/archive/2011/06/29/6573967.aspx


相关阅读:
Top