vs10已经具备了查看设计界面的功能,那为什么我的vs中总是会弹出这个东东,无法看到界面呢,异常为:“未将对象引用设置到对象的实例”

我做了个实验:当代码为:<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/up-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <Grid x:Name="LayoutRoot" Background="White">
    </Grid>
</UserControl>
无法显示界面,当把上面的代码中的 <Grid/>替换成<StackPanel />就ok啦。why?why?why?

解决方案 »

  1.   

    SilverlightApplication1.MainPage看这个东西构造函数里面做什么了。
      

  2.   

    public MainPage()
            {
                InitializeComponent();
            }
     public void InitializeComponent() {
                if (_contentLoaded) {
                    return;
                }
                _contentLoaded = true;
                System.Windows.Application.LoadComponent(this, new System.Uri("/SilverlightApplication1;component/MainPage.xaml", System.UriKind.Relative));
                this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
            }