xaml用户控件对象引用未设置为对象的实例

xaml用户控件对象引用未设置为对象的实例,xaml,windows-8,Xaml,Windows 8,我有一个相当简单的Windows 8 XAML/C用户控件: <UserControl x:Class="periodicTable.cell" x:Name="periodicTableCell" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmln

我有一个相当简单的Windows 8 XAML/C用户控件:

  <UserControl
    x:Class="periodicTable.cell"
    x:Name="periodicTableCell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:periodicTable"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="100"
    d:DesignWidth="65">

<Grid Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="15"/>
        <RowDefinition Height="20"/>
        <RowDefinition Height="50"/>
        <RowDefinition Height="15"/>
    </Grid.RowDefinitions>
    <TextBlock Grid.Row="0" x:Name="txtElementName"/>
    <TextBlock Grid.Row="1" x:Name="txtAtomicNumber"/>
    <TextBlock Grid.Row="2" x:Name="txtSymbol"/>
    <TextBlock Grid.Row="3" x:Name="txtAtomicWeight"/>
</Grid>
将此控件添加到主页XAML时:

xmlns:local="using:periodicTable"
然后,当我尝试将其添加到我的网格时:

<local:cell Grid.Row="0" Grid.Column="2"/>
我得到一个错误声明:对象引用未设置为对象的实例

我应该注意到,我计划在许多行和列中重用此用户控件


我做错了什么?

元素名称、原子编号、符号和原子权重似乎未初始化。它们的值将为null,.ToString方法将失败。首先尝试将它们初始化为空字符串。

elementName、atomicNumber、symbol和atomicWeight似乎未初始化。它们的值将为null,.ToString方法将失败。首先尝试将它们初始化为空字符串。

谢谢。这就是答案。谢谢。这就是答案。
<local:cell Grid.Row="0" Grid.Column="2"/>