简体   繁体   中英

Visual Studio 2008 WPF designer won't load my forms

I'm trying to see a form developed by someone else (ex-employee) in Visual Studio 2008 but keep running into the following error when I try and look at MainForm.xaml (it fails to load in the designer view):

Error Could not create an instance of type 'NumericTextBox'. D:\\MySolution\\GUI\\MainForm.xaml

My solution is organised something like this (shortened for brevity - it's the last line of this where the error occurs):

\solution
    \Gui
        \App.xaml
        \MainForm.xaml
    \Utils
        \NumericTextBox.cs

My MainForm.xaml looks something like this:

<Window x:Class="MyCompany.MyDepartment.MyProject.MainForm"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MyCompany.MyDepartment.MyProject"
        xmlns:myproject="clr-namespace:MyCompany.MyDepartment.MyProject;assembly=MyProject"
        xmlns:dsp="clr-namespace:MyCompany.MyDepartment.MyProject.DSP;assembly=MyProject"
        xmlns:filters="clr-namespace:MyCompany.MyDepartment.DSP.Filters;assembly=DSP"
        xmlns:mydepartment="clr-namespace:MyCompany.MyDepartment.Utils;assembly=Utils"
        xmlns:scope="clr-namespace:MyCompany.MyDepartment;assembly=ScopeControl"
        Title="MyProject" Height="900" Width="1024"
        Loaded="Window_Loaded"
        Closing="Window_Closing" ResizeMode="CanResize" Icon="/MyProjectGUI;component/MyProjectGUI.ico">

    <Window.Resources>
    ...
    </Window.Resources>

    <DockPanel>
        <StackPanel DockPanel.Dock="Left" CanVerticallyScroll="True" CanHorizontallyScroll="False">
            <GroupBox Name="SensorControlGroup"  Header="Sensor Control">
            ...
            </GroupBox>
            <GroupBox Header="Sensor State">
                <StackPanel Name="SensorStackPanel">
                    <Expander Name="EnvironmentExpander" Header="Environment">
                    ...
                    </Expander>
                    <Expander Name="SynthExpander" Header="Synthesiser" IsExpanded="True">
                        <Border Margin="2" Background="White" Padding="3">
                            <Grid>                                
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="120"/>
                                    <ColumnDefinition Width="60"/>
                                    <ColumnDefinition Width="60"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <Label Grid.Column="0" Grid.Row="0">Frequency (MHz):</Label>

                                <mydepartment:NumericTextBox Grid.Column="1"
                                                     x:Name="SynthFrequency" DecimalPlaces="3"
                                                     Maximum="0" Minimum="0" />

What might cause that error? Everything compiles okay but the application crashes when I run it . I was hoping the two problems might be a related issue.

The two issues you mentioned are almost certainly related. In both cases, the XAML file will be processed in order to create a control. One for design purposes and the other for runtime. If there is an exception being generated at runtime while parsing the file then it follows that the designer will also be having problems with the file.

I think you need to focus on the original bug and then come back to this one. One should almost certainly fix the other.

Okay, so it turned out that although Visual Studio was set up to use v3.5 of the .net framework you need to seperately install v3.5 of the framework - it seems I only had v2 installed. Let this be a lesson for anyone else struggling with the same problems!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM