2010-10-04 11 views
1

Disons que nous avons le code ci-dessous:Comment ajouter un commentaire pour une définition d'attribut à partir d'un tag?

<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"> 

Et nous voulons ajouter un commentaire à la ligne MinWidth = « 800 » MinHeight = « 600 » dire « Ceci est la largeur/hauteur minimale de l'application ". J'ai essayé:

<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"> 

Mais cela a déclenché une erreur. Alors, comment puis-je faire ça?

Répondre

2

Il n'est pas possible d'ajouter un commentaire à un attribut de cette manière. XAML est un dialecte XML et suit donc les règles syntaxiques du langage XML qui l'interdisent. Les commentaires XML ne peuvent apparaître qu'en dehors d'autres éléments de balisage (ou plus simplement en dehors des autres balises d'éléments XML).

L'emplacement le plus proche qui peut être ajouté est avant ou après l'élément <Window>.

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

> <!-- Legal --> 
0
  1. espace de noms ajouter: xmlns:comment="my comment"

  2. l'ignorer: mc:Ignorable="comment"

Astuce: si vous ignorant déjà un nom d'espace comme xmlns:d="http://schemas.microsoft.com/expression/blend/2008" simplement rejoindre ces namespace en utilisant l'espace: mc:Ignorable="a comment"

  1. utiliser: Code Mise à jour:
<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>