0

我在 Windows Phone 8 应用程序中有一个页面,用户可以在其中将项目链接到组 (n:1)。该组是通过 Toolkit ListPicker 控件选择的。ListPicker 下方是一个取消链接按钮,用于删除从项目到组的链接。

    <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>

如果用户从组中取消链接项目,我想将 ListPicker 的 SelectedItem 设置为 null(未选择组)。仅将 SelectedItem 设置为 null 或将 SelectedIndex 设置为 -1 不起作用(例外:设置有效值...)。

有人对这个问题有想法吗?

//编辑:我正在寻找一种解决方法,而不是编译我自己的 ListPicker 控件。

4

1 回答 1

0

加入一个初始字符串值怎么样<System:String>Choose Item...</System:String>,它也可以作为提示,然后你可以在代码中引用它,然后GorupList.SelectedIndex = 0;在选择时忽略你的代码?

        <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>

非常正确:你能抓住这个解决方案PhoneApp5看看它是否更符合你的要求吗?然后你或我可以发布代码(我的原样或你的改进)。

于 2013-03-24T20:43:36.690 回答