2009-03-22 9 views
0

Est-ce que quelqu'un sait de la raison pour laquelle "" n'a pas pu créer l'instance de UserControl "" erreur peut se produire. Il me semble que cela se produit de façon complètement spontanée, par exemple après avoir ajouté de l'espace après le nœud ou changé la tabulation. Peut-être que c'est une sorte de bug VS?Erreurs WPF étranges dans Visual Studio

Voici les contrôles. Cette configuration génère en fait une erreur

<UserControl x:Class="ShortcutsPrototype.KeyboardShortcutsTreePanel" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:ShortcutsPrototype="clr-namespace:ShortcutsPrototype"> 


    <Grid Margin="3,3,3,3"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition /> 
      <ColumnDefinition Width="80" /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition /> 
      <RowDefinition Height="30" /> 
     </Grid.RowDefinitions> 


     <ShortcutsPrototype:KeyboardShortcutsTreeView /> 
     <Button Grid.Row="1" Margin="3,3,3,3" Grid.Column="1" HorizontalAlignment="Stretch">Reset</Button> 
    </Grid> 
</UserControl> 


<UserControl x:Class="ShortcutsPrototype.KeyboardShortcutsTreeView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:ShortcutsPrototype="clr-namespace:ShortcutsPrototype" 
    Height="300" Width="300"> 

    <Grid> 
     <TreeView> 
      <TreeViewItem HorizontalContentAlignment="Stretch"> 
       <TreeViewItem.Header> 
        <ShortcutsPrototype:KeyboardShortcutsTreeViewEntry x:Name="generalTreeViewEntry" Title="General" /> 
       </TreeViewItem.Header> 

       <TreeViewItem HorizontalContentAlignment="Stretch"> 
        <TreeViewItem.Header> 
         <ShortcutsPrototype:KeyboardShortcutsTreeViewEntry x:Name="generalNewFileTreeViewEntry" Title="New File" ShortcutKey="Ctrl+N" /> 
        </TreeViewItem.Header> 
       </TreeViewItem> 

       <TreeViewItem HorizontalContentAlignment="Stretch"> 
        <TreeViewItem.Header> 
         <ShortcutsPrototype:KeyboardShortcutsTreeViewEntry x:Name="generalOpenFileTreeViewEntry" Title="Open File" ShortcutKey="Ctrl+O" /> 
        </TreeViewItem.Header> 
       </TreeViewItem> 

       <TreeViewItem HorizontalContentAlignment="Stretch"> 
        <TreeViewItem.Header> 
         <ShortcutsPrototype:KeyboardShortcutsTreeViewEntry x:Name="generalSaveFileTreeViewEntry" Title="Save File" ShortcutKey="Ctrl+S" /> 
        </TreeViewItem.Header> 
       </TreeViewItem> 

       <TreeViewItem HorizontalContentAlignment="Stretch"> 
        <TreeViewItem.Header> 
         <ShortcutsPrototype:KeyboardShortcutsTreeViewEntry x:Name="generalSaveAsFileTreeViewEntry" Title="Save File As.." ShortcutKey="Ctrl+Shift+S" /> 
        </TreeViewItem.Header> 
       </TreeViewItem> 

      </TreeViewItem> 
      <TreeViewItem HorizontalContentAlignment="Stretch"> 
       <TreeViewItem.Header> 
        <ShortcutsPrototype:KeyboardShortcutsTreeViewEntry x:Name="debugerTreeViewEntry" Title="Debuger" /> 
       </TreeViewItem.Header> 
      </TreeViewItem> 
      <TreeViewItem HorizontalContentAlignment="Stretch"> 
       <TreeViewItem.Header> 
        <ShortcutsPrototype:KeyboardShortcutsTreeViewEntry x:Name="refactoringTreeViewEntry" Title="Refactoring" /> 
       </TreeViewItem.Header> 
      </TreeViewItem> 
     </TreeView> 
    </Grid> 
</UserControl> 



<UserControl x:Class="ShortcutsPrototype.KeyboardShortcutsTreeViewEntry" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Height="25"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition /> 
      <ColumnDefinition Width="100" /> 
     </Grid.ColumnDefinitions> 
     <Label x:Name="titleLabel" Grid.Column="0"></Label> 
     <Label x:Name="shortcutLabel" Grid.Column="1"></Label> 
    </Grid> 
</UserControl> 

Répondre

1

Il se peut que quelque chose dans votre fichier CodeBehind lève une exception. Avez-vous vérifié cela?

+0

Hm, vous avez probablement raison. Je croyais en ReSharper et jeté l'extension de la classe UserControl dans le code derrière. Après l'avoir lu, cela a de nouveau fonctionné sans problèmes –

0

J'ai trouvé que Visual Studio a tout à fait du mal avec les contrôles utilisateur WPF.

La seule chose que je peux voir est qu'il semble utiliser la dernière version compilée d'un contrôle. Habituellement, la construction de la solution va corriger les erreurs que j'ai. Parfois, si j'ai plusieurs projets, je dois les construire manuellement un par un.

+0

Ouais, c'est frustrant –

Questions connexes