我正在尝试使用列表框来显示自定义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>
答案 0 :(得分:1)
答案 1 :(得分:0)
尝试:
<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>