0
votes

I have a page in a Windows Phone 8 app where the user can link items to a group (n:1). The group is selected via the Toolkit ListPicker control. Under the ListPicker is a unlink button for removing the link from item to group.

    <StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <toolkit:ListPicker x:Name="GorupList"
                            Header="Background" 
                            ExpansionMode="FullscreenOnly" 
                            ItemsSource="{Binding}" 
                            SelectionChanged="GroupList_SelectionChanged">
            <toolkit:ListPicker.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </toolkit:ListPicker.ItemTemplate>
            <toolkit:ListPicker.FullModeItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="16 21 0 20">
                        <TextBlock Text="{Binding Name}"
                                   FontSize="43" 
                                   FontFamily="{StaticResource PhoneFontFamilyLight}"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.FullModeItemTemplate>
        </toolkit:ListPicker>
        <Button x:Name="UnlinkButton" Content="Unlink" Click="OnUnlink" />
    </StackPanel>

If the usere unlinks a item from a group, I want to set the SelectedItem of the ListPicker to null (no group selected). Just setting SelectedItem to null or SelectedIndex to -1 does not work (Exception: set valid value...).

Does anybody have an idea for this issue?

//EDIT: I'm looking for a workaround, not compiling a my own ListPicker control.

1
A possible solution is to set a transparent Rectangle as overlay and listen to the tap event and call Listpicker.Open() manually. The problem is that the pressed effect of the ListPicker isn't shown.zrkl
I have also tried a Converter which returns Visibility.Collapsed if the Group name is null...zrkl

1 Answers

0
votes

How about dropping in an initial string value <System:String>Choose Item...</System:String> , which can also act as a prompt, then you can refer to it in code GorupList.SelectedIndex = 0; and subsequently ignore in your code behind when selected?

        <StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <toolkit:ListPicker x:Name="GorupList"
                        Header="Background" 
                        SelectionChanged="GroupList_SelectionChanged">
            <toolkit:ListPicker.FullModeItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="16 21 0 20">
                        <TextBlock Text="{Binding Name}"
                               FontSize="43" 
                               FontFamily="{StaticResource PhoneFontFamilyLight}"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.FullModeItemTemplate>
            <System:String>Choose Item...</System:String>
        </toolkit:ListPicker>
        <Button x:Name="UnlinkButton" Content="Unlink" Click="OnUnlink" />
    </StackPanel>

Quite right: Could you grab this solution PhoneApp5 and see if it's more to your requirements? Then either you or I can post up the code (mine as is or yours improved).