0

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

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

如果usere从一组解除链接一个项目,我想设置ListPicker的的SelectedItem为空(无选择的组)。只是将SelectedItem设置为null或将SelectedIndex设置为-1不起作用(例外:设置有效值...)。

有没有人有这个问题的想法?

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

+0

一种可能的解决方案是将透明Rectangle设置为叠加并收听轻敲事件并手动调用Listpicker.Open()。问题是没有显示ListPicker的按下效果。 – 2013-03-25 19:49:39

+0

我也尝试了一个*转换器*,它返回* Visibility.Collapsed *如果组名为空... – 2013-03-26 18:19:17

回答

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,看看它是否更合你的要求吗?然后,你或我可以张贴代码(我的或改进)。

+0

它是否可以与绑定一起使用? – 2013-03-25 08:03:31

+0

它不适用于绑定! – 2013-03-25 17:48:58

相关问题