“无效的xaml”设计者的错误

发布于 2025-01-07 12:30:27 字数 2418 浏览 0 评论 0原文

我正在尝试使用列表框来显示自定义用户控件。它一直工作得很好,直到最近我开始收到“无效的 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 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>

I am trying to use a listbox to display a custom UserControl. It had been working just fine until recently i started recieving an "invalid xaml" error message and am no long able to refresh the Design View.

The error does not keep the app from compiling and running.

I have tried everything i can think of. I created a test control and a test page from scratch and only get the error when i put the control in the data template. I can put any standard control into the data template without error. only errors on a custom usercontrol.

here is the page:

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

and here is the usercontrol (no added code in the codebehind):

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是偏爱你 2025-01-14 12:30:28
  1. 有时这是由于缺少资源而触发的。
  2. 还缺少一个 。标签。

尝试:

<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>
  1. Sometimes this is triggered by missing resources.
  2. There is also a missing </UserControl> tag.

try:

<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>
若有似无的小暗淡 2025-01-14 12:30:27

好的,我根据这篇文章弄清楚了

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

我不敢相信我在程序集名称中添加了一个空格。 ARG!

Ok, I figured it out based on this post

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

I cannot believe I added a space to my assembly name. ARG!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文