McK*_*Kay 14 inheritance silverlight-toolkit windows-phone-7 longlistselector
我正在尝试从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);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将它添加到LongListSelector示例中,与所有其他长列表选择器位于相同的轴中:
<controls:PivotItem Header="SLLS">
<local:SimpleLongListSelector x:Name="simple" />
</controls:PivotItem>
Run Code Online (Sandbox Code Playgroud)
然后我添加它的源与LoadLinqMovies()中的电影源相同
simple.ItemsSource = moviesByCategory;
Run Code Online (Sandbox Code Playgroud)
然后运行代码(我知道它看起来不漂亮,那是因为绑定没有设置正确,我这样做所以你知道它不是数据.如果你愿意,你可以这样做:
simple.ItemsSource = movies.GroupBy((m) => m.Title[0]).Select((c) => new PublicGrouping<char, Movie>(c));
Run Code Online (Sandbox Code Playgroud)
看起来我希望它看起来像.
好吧,在任何一种情况下,这都按预期工作,除非我点击组头.(任何[默认为蓝色]方块).我得到了
WrappedException
Run Code Online (Sandbox Code Playgroud)
错误消息是:
0xc00cee3c
Run Code Online (Sandbox Code Playgroud)
我认为这意味着:
well-formedness constraint: unique attribute spec
Run Code Online (Sandbox Code Playgroud)
我不认为我有一个独特性问题.我究竟做错了什么?
如果您使用 7.1 工具包中的 LongListSelector(位于http://silverlight.codeplex.com/releases/view/71550),则您的示例代码将按上面列出的方式工作。这一定是原始 LLS 中的一些错误......