设计器中出现“无效的xaml”错误

时间:2012-02-20 15:56:02

标签: silverlight windows-phone-7

我正在尝试使用列表框来显示自定义UserControl。它一直工作得很好直到最近我开始收到“无效的xaml”错误消息,并且我不能再刷新设计视图。

错误不会阻止应用程序编译和运行。

我已经尝试了我能想到的一切。我从头开始创建了一个测试控件和一个测试页面,只有在我将控件放入数据模板时才会出错。我可以将任何标准控件放入数据模板中而不会出错。只有自定义用户控件上的错误。

这是页面:

<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WP7ListBoxSelectedItemStyle"
xmlns:my="clr-namespace:testproject.Controls"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
x:Class="WP7ListBoxSelectedItemStyle.TestPage"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="8,17,16,-17">
        <ListBox  Name="lb_test"
                        Margin="0,0,0,0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <my:Test1></my:Test1>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Grid>

这是usercontrol(代码隐藏中没有添加代码):

<UserControl x:Class="testproject.Controls.Test1"
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/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
Height="80" Width="80">

<Grid x:Name="LayoutRoot">

</Grid>
</UserControl>

2 个答案:

答案 0 :(得分:1)

好的,我根据这篇文章找出了它

http://forums.silverlight.net/post/618518.aspx

我无法相信我在程序集名称中添加了空格。 ARG!

答案 1 :(得分:0)

  1. 有时这是由资源缺失引发的。
  2. 还缺少&lt; / UserControl&gt;标签
  3. 尝试:

    <UserControl x:Class="testproject.Controls.Test1"
    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/markup-compatibility/2006"
    mc:Ignorable="d"
    Height="80" Width="80">
    
      <Grid x:Name="LayoutRoot">
    
      </Grid>
    </UserControl>
    
相关问题