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

相關問題