代码之家  ›  专栏  ›  技术社区  ›  Nam G VU

如何从标记内为属性定义添加注释?

  •  1
  • Nam G VU  · 技术社区  · 14 年前

    假设我们有以下代码:

    <Window 
        x:Class="Consus.Client.UI.Sandbox.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
    
        x:Name="RibbonWindow"
        Width="800" Height="600"
        MinWidth="800" MinHeight="600"
        Title="MainWindow">
    

    我们想在这一行添加评论 minwidth=“800”minheight=“600” “这是应用程序的最小宽度/高度” . 我尝试过:

    <Window 
            x:Class="Consus.Client.UI.Sandbox.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
    
            x:Name="RibbonWindow"
            Width="800" Height="600"
            MinWidth="800" MinHeight="600" <!--My comment goes here-->
            Title="MainWindow">
    

    但这引发了一个错误。那我该怎么做呢?

    2 回复  |  直到 9 年前
        1
  •  2
  •   JaredPar    14 年前

    以这种方式向属性添加注释是不可能的。XAML是一种XML方言,因此遵循XML的语法规则,不允许这样做。XML注释只能出现在其他标记元素之外(或更简单地出现在其他XML元素标记之外)。

    可以添加的最近位置是 <Window> 元素。

    <!-- Legal --> 
    <Window
      ...
    
    > <!-- Legal -->
    
        2
  •  0
  •   Peter Dub    9 年前
    1. 添加命名空间: xmlns:comment="my comment"

    2. 忽略它: mc:Ignorable="comment"

    提示: 如果您已经忽略了类似 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 只需使用空格连接这些命名空间: mc:Ignorable="a comment"

    1. 使用它: 更新代码:
    <Window 
    x:Class="Consus.Client.UI.Sandbox.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
    x:Name="RibbonWindow"
    Width="800" Height="600"
    MinWidth="800" comment:MinWidth="Some comment for MinWidth"
    MinHeight="600" comment:MinWidth="Some comment for MinHeight"
    Title="MainWindow">
    ...
    </Window>