我正在尝试从 silverlight 工具包 LongListSelector 创建一个后代类。我们称它为 SimpleLonglistSelector。我从“Silverlight for Windows Phone Toolkit Source & Sample - Feb 2011.zip”开始
http://silverlight.codeplex.com/releases/view/60291
我创建了一个新类:
public class SimpleLongListSelector : LongListSelector
{
public SimpleLongListSelector()
{
var itemsPanelTemplate = @"
<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/client/2007'>
<toolkit:WrapPanel xmlns:toolkit='clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit' Orientation=""Horizontal""/>
</ItemsPanelTemplate>";
this.GroupItemsPanel = (ItemsPanelTemplate)XamlReader.Load(itemsPanelTemplate);
var groupItemTemplate = @"
<DataTemplate xmlns='http://schemas.microsoft.com/client/2007'>
<Border Width=""99"" Height=""99"" Background=""{StaticResource PhoneAccentBrush}"" Margin=""6"" IsHitTestVisible=""{Binding HasItems}"">
<TextBlock Text=""{Binding Key}""
FontFamily=""{StaticResource PhoneFontFamilySemiBold}""
FontSize=""36""
Margin=""{StaticResource PhoneTouchTargetOverhang}""
Foreground=""{StaticResource PhoneForegroundBrush}""
VerticalAlignment=""Bottom""/>
</Border>
</DataTemplate>";
this.GroupItemTemplate = (DataTemplate)XamlReader.Load(groupItemTemplate);
var groupHeaderTemplate = @"
<DataTemplate xmlns='http://schemas.microsoft.com/client/2007'>
<Border Background=""Transparent"">
<Border Background=""{StaticResource PhoneAccentBrush}"" Width=""75"" Height=""75"" HorizontalAlignment=""Left"">
<TextBlock Text=""{Binding Path=Key}""
Foreground=""{StaticResource PhoneForegroundBrush}""
Style=""{StaticResource PhoneTextExtraLargeStyle}""
VerticalAlignment=""Bottom""/>
</Border>
</Border>
</DataTemplate>";
this.GroupHeaderTemplate = (DataTemplate)XamlReader.Load(groupHeaderTemplate);
var itemTemplate = @"
<DataTemplate xmlns='http://schemas.microsoft.com/client/2007'>
<TextBlock Text=""{Binding Title}"" FontSize=""30""/>
</DataTemplate>";
this.ItemTemplate = (DataTemplate)XamlReader.Load(itemTemplate);
}
}
然后我将它添加到 LongListSelector 示例中,与所有其他长列表选择器在同一个轴中:
<controls:PivotItem Header="SLLS">
<local:SimpleLongListSelector x:Name="simple" />
</controls:PivotItem>
然后我添加它的源与 LoadLinqMovies() 中的电影源相同
simple.ItemsSource = moviesByCategory;
然后运行代码(我知道它看起来不漂亮,那是因为绑定设置不正确,我这样做是为了让你知道它不是数据。如果你愿意,你可以这样做:
simple.ItemsSource = movies.GroupBy((m) => m.Title[0]).Select((c) => new PublicGrouping<char, Movie>(c));
看起来我希望它看起来。
好吧,无论哪种情况,这都按预期工作,除非我单击组标题。(任何 [默认为蓝色] 方块)。我得到一个
WrappedException
错误信息是:
0xc00cee3c
我认为这意味着:
well-formedness constraint: unique attribute spec
我认为我没有唯一性问题。我究竟做错了什么?