Странные ошибки WPF в Visual Studio - PullRequest
0 голосов
/ 22 марта 2009

Кто-нибудь знает причину, по которой может возникать ошибка "" не удалось создать экземпляр UserControl "". Мне кажется, что это происходит совершенно спонтанно, например, после того, как я добавляю пробел после узла или меняю табуляцию. Может быть, это какая-то ошибка VS?

Вот элементы управления. Эта конфигурация фактически вызывает ошибку

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

Ответы [ 2 ]

1 голос
/ 22 марта 2009

Возможно, что-то в вашем файле CodeBehind вызывает исключение. Вы это проверяли?

0 голосов
/ 22 марта 2009

Я обнаружил, что Visual Studio довольно сложно работать с пользовательскими элементами управления WPF.

Единственное, что я вижу, это то, что он использует последнюю скомпилированную версию элемента управления. Обычно построение решения исправит ошибки, которые у меня есть. Иногда, если у меня есть несколько проектов, мне приходится создавать их вручную один за другим.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...