zoukankan      html  css  js  c++  java
  • WPF 自定义ContextMenu且为左键点击显示

     1<Button Click="Button_Click_3"  Style="{StaticResource NormalButtonStyle}">
     2  <Canvas>
     3    <Line X1="-5" Y1="-4" X2="5" Y2="-4" Fill="White" Stroke="White" StrokeThickness="1"/>
     4    <Line X1="-5" Y1="-4" X2="-5" Y2="4" Fill="White" Stroke="White" StrokeThickness="1"/>
     5    <Line X1="-5" Y1="4" X2="5" Y2="4" Fill="White" Stroke="White" StrokeThickness="1"/>
     6    <Line X1="5" Y1="-4" X2="5" Y2="4" Fill="White" Stroke="White" StrokeThickness="1"/>
     7  </Canvas>
     8  <Button.ContextMenu>
     9    <ContextMenu Name="menu" Placement="MousePoint" Width="200">
    10      <MenuItem Header="Item1"/>
    11      <MenuItem Header="Item2"/>
    12      <MenuItem Header="Item3"/>
    13      <MenuItem Header="Item4"/>
    24    </ContextMenu>
    25  </Button.ContextMenu>
    26</Button>


    上为XAML设计代码,Style部分是Button的样式。
    Canvas内的代码是Line,图案是一个方框。怎么修改可自行百度

    左键显示Menu代码如下
            private void Button_Click_3(object sender, RoutedEventArgs e)
            {
                //获取或设置一个值,该值指示 System.Windows.Controls.ContextMenu 是否可见。
                this.menu.IsOpen = true;
            }
    
    
    
     
  • 相关阅读:
    蓝桥杯--芯片测试
    蓝桥杯--FJ的字符串
    win8 js 没反应
    winform win8 js checkbox互动
    win8 GridView
    wcf服务引用无实体类对象
    arcgis 接口转换与.Net框架
    win8 链接
    分页控件
    Oracle 分页查询存储过程
  • 原文地址:https://www.cnblogs.com/SunsetAzure/p/4711511.html
Copyright © 2011-2022 走看看