Conventions for LongListSelector in WP7 toolkit?

Feb 13, 2011 at 4:40 PM

The LongListSelector control in WP7 Silverlight Toolkit used some complex methods to render its items. It didn't derive from Selector or ItemsControl. I read the documentation of conventions but had no idea how to make this work.

And about its ListHeaderTemplate, LongListSelector also used its own way to render that, so binding didn't work either. Setting the ListHeader directly seemed to be working but it would crash under certain circumstances (it's its own issue though).

Has anyone tried to implement the convention for LongListSelector? Any suggestions would be great.

Regards.

Feb 14, 2011 at 12:05 PM

With LongListSelector didn't seem to work. Then I tried to do the list-header with normal listbox.

However, attaching the View.Model property in the style didn't work. This would go into a runtime error. Said "Unknown namespace http://www.caliburnproject.org". But I did include the namespace.

Here's the code:

 

<UserControl.Resources>
    <Style x:Key="HeaderListBox" TargetType="ListBox">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <Grid>
                        <ScrollViewer x:Name="ScrollViewer"
                                      BorderBrush="{TemplateBinding BorderBrush}"
                                      BorderThickness="{TemplateBinding BorderThickness}"
                                      Background="{TemplateBinding Background}"
                                      Foreground="{TemplateBinding Foreground}"
                                      Padding="{TemplateBinding Padding}">
                            <StackPanel>
                                <ContentControl x:Name="ListHeader" cal:View.Model="{Binding ListHeader}" />
                                <ItemsPresenter/>
                            </StackPanel>
                        </ScrollViewer>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

<ListBox x:Name="Items" ItemsSource="{Binding Items}"
         Style="{StaticResource HeaderListBox}">
    <ListBox.ItemTemplate>
        <DataTemplate>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>