2014-05-17 76 views
0

我的項目中有LongListMultiSelector,它與ListProductInRecipe2P綁定。當我用LongListMultiSelector加載頁面時,列表正在加載,但是當我想要刪除時,項目LongListMultiSelector不是正在更新。WP8 LongListMultiSelector - 不綁定


這是我的代碼: XAML:

<toolkit:LongListMultiSelector x:Name="ListProductsSelectedItems" ItemsSource="{Binding ListProductInRecipe2P}"> 
    <toolkit:LongListMultiSelector.ItemTemplate> 
     <DataTemplate> 
      <StackPanel> 
       <TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextGroupHeaderStyle}"></TextBlock> 
       <StackPanel Orientation="Horizontal"> 
        <TextBlock Text="{Binding Size}" Style="{StaticResource PhoneTextNormalStyle}"></TextBlock> 
        <TextBlock Text="{Binding Type}" Style="{StaticResource PhoneTextNormalStyle}"></TextBlock> 
       </StackPanel> 
      </StackPanel> 
     </DataTemplate> 
    </toolkit:LongListMultiSelector.ItemTemplate> 
</toolkit:LongListMultiSelector> 

C#(代碼隱藏):

private void DelProducts_Click(object sender, EventArgs e) 
{ 
    var list = ListProductsSelectedItems.SelectedItems; 
    for (int i = 0; i < list.Count; i++) 
    { 
     var temp = list[i] as Fridge; 
     App.ViewModel.ListProductInRecipe2P.Remove(temp); 
    } 
} 

和C#(視圖模型):

private List<Fridge> ListProductInRecipe2; 
public List<Fridge> ListProductInRecipe2P 
{ 
    get { return ListProductInRecipe2;} 
    set 
    { 
     ListProductInRecipe2 = value; 
     changeValue("ListProductInRecipe2P"); 
    } 
} 

回答

1

嘗試使用ObservableCollection。它會爲您提升INotifyProperty事件。

瞭解更多@MSDN ObservableCollection Class


using System.Collections.ObjectModel; 

private ObservableCollection<Fridge> ListProductInRecipe2; 
public ObservableCollection<Fridge> ListProductInRecipe2P 
{ 
    get { return ListProductInRecipe2;} 
    set 
    { 
     ListProductInRecipe2 = value; 
     // changeValue("ListProductInRecipe2P"); 
    } 
} 
相關問題