2010-10-04 137 views
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" 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

以这种方式添加注释到属性是不可能的。 XAML是一种XML方言,因此遵循XML的合成规则,否定这一点。 XML注释只能出现在其他标记元素之外(或者更简单地在其他XML元素标记之外)。

可以添加的最接近的位置是在<Window>元素之前或之后。

<!-- Legal --> 
<Window 
    ... 

> <!-- Legal --> 
0
  1. 添加命名空间:xmlns:comment="my comment"

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

提示:如果你已经忽略了一些命名空间像xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 刚刚加入使用空间,这些命名空间: mc:Ignorable="a comment"

  • 使用它: 更新代码:
  • <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> 
    
    相关问题