列表选择器选择更改

时间:2015-04-21 02:55:11

标签: windows-phone-7 windows-phone-8 windows-phone windows-phone-8.1

我有2个列表选择器,显示项目名称和批号。批号取决于项目名称。因此,当选择项目名称时,我想将批次编号绑定到第二个列表选择器。我的代码是这样的。我为Item list picker 'SelectionChanged'事件编写了代码。这不起作用。

  private void lstItem_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (lstItem.SelectedIndex != 0)
        {
            int itemId = invoice.listItems[lstItem.SelectedIndex].ItemMasterID;
            getBatches = invoice.bindBatchesForItem(itemId);
            lstBatch.ItemsSource = getBatches;                
        }
    }

bindBatchesForItem将返回所选项目的批次编号列表。此方法正确返回批次。但'lstItem_SelectionChanged'事件会自动调用twise。第一次正确执行,第二次执行附加错误时,ERROR

public ObservableCollection<BatchNumbers> bindBatchesForItem(int selectedItem)
    {
        listBatches.Clear();
        var batchList = from DailyItemStock DI in APPCommon.SFADB
                        where Convert.ToDateTime(DI.StockDate).Date == Convert.ToDateTime(APPCommon.TransactionDate).Date && DI.ItemMasterID == selectedItem
                        select new
                        {
                            DI.BatchNo
                        };

        listBatches.Add(new BatchNumbers() { BatchNo = "0" });
        foreach (var lists in batchList)
        {
            listBatches.Add(new BatchNumbers()
            {
                BatchNo = lists.BatchNo.ToString()                
            });
        }          
        batchList = null;
        return listBatches;
    }

Screen

0 个答案:

没有答案