WindowChrome - 如何修改或禁用标题栏中的上下文菜单?

时间:2015-08-25 16:03:42

标签: wpf contextmenu

我需要在使用WindowChrome的WPF窗口的标题栏中禁用上下文菜单:

<Window x:Class="WpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        ContextMenu="{x:Null}">
    <WindowChrome.WindowChrome>
        <WindowChrome CaptionHeight="35"
                      CornerRadius="0"
                      ResizeBorderThickness="5"
                      UseAeroCaptionButtons="False" />
    </WindowChrome.WindowChrome>
</Window>

文本菜单=&#34; {X:空}&#34;不起作用。 以下说明也不起作用: http://codereply.com/answer/7etz8e/remove-title-bars-context-menu-completely-wpf-window.html 标题栏中的上下文菜单始终显示为无变化。 有人有想法吗?

1 个答案:

答案 0 :(得分:0)

  // Enter any new nodes
  this.node.enter().append('defs')
        .append('pattern')
            .attr('id', function(d) { return (d.id+"-icon-img");}) // just create a unique id (id comes from the json)
            .attr('patternUnits', 'userSpaceOnUse')
            .attr('width', 80)
            .attr('height', 80)
            .append("svg:image")
                .attr("xlink:xlink:href", function(d) { return (d.icon);}) // "icon" is my image url. It comes from json too. The double xlink:xlink is a necessary hack (first "xlink:" is lost...).
                .attr("x", 0)
                .attr("y", 0)
                .attr("height", 80)
                .attr("width", 80)
                .attr("preserveAspectRatio", "xMinYMin slice");

  this.node.enter().append('svg:circle')
    .attr("class", "node CodeFlowerNode")
    .classed('directory', function(d) { return (d._children || d.children) ? 1 : 0; })
    .attr("r", function(d) { return d.children ? 3.5 : Math.pow(d.size, 2/5) || 1; })
    .style("fill", function(d) { return ("url(#"+d.id+"-icon-img)");})
    /* .style("fill", function color(d) {
      return "hsl(" + parseInt(360 / total * d.id, 10) + ",90%,70%)";
    })*/
    .call(this.force.drag)
    .on("click", this.click.bind(this))
    .on("mouseover", this.mouseover.bind(this))
    .on("mouseout", this.mouseout.bind(this));