【问题标题】:Get Value for selected Item in ListPicker获取 ListPicker 中选定项目的值
【发布时间】:2015-04-17 14:16:34
【问题描述】:

我有一个显示项目名称的列表选择器。选择一个项目时,我想获取该选定项目的项目 ID。我该怎么做?

<toolkit:ListPicker x:Name="lstItem" 
                                            FullModeHeader="Item"
                                            SelectionMode="Single" 
                                            ItemsSource="{Binding getItems}"  
                                            ExpansionMode="FullscreenOnly"  
                                            Margin="12,5,10,0" 
                                            Grid.Row="0" 
                                            Grid.Column="1"

                                            Background="White"
                                            FontSize="21"
                                            Header="" 
                                            Foreground="Black"
                                            BorderThickness="0" Grid.ColumnSpan="2" SelectionChanged="lstItem_SelectionChanged"
                                     >
                            <toolkit:ListPicker.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}"  />                                        
                                </DataTemplate>                                    
                            </toolkit:ListPicker.ItemTemplate>
                            <toolkit:ListPicker.FullModeItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Margin="16 15 0 15">
                                        <TextBlock Text="{Binding Name}"
                                   Margin="0 0 0 0"
                                   FontSize="25" 
                                   FontFamily="{StaticResource PhoneFontFamilyLight}"/>
                                    </StackPanel>
                                </DataTemplate>
                            </toolkit:ListPicker.FullModeItemTemplate>
                        </toolkit:ListPicker>

在 C# 代码中,我将两者都绑定到 listpicker。这个数据直接绑定到 list picker。

public ObservableCollection<Items> bindItems()
    {
        listItems.Clear();
        //int i = Common.intCustomerId; //&& btypes.ChqRtnPaymentNo == ""
        var itemlist = from DailyItemStock DailyItm in APPCommon.SFADB
                       join ItemMaster IM in APPCommon.SFADB on DailyItm.ItemMasterID equals IM.ID
                       where DailyItm.StockDate == System.DateTime.Today
                       select new
                       {
                           DailyItm.ItemMasterID,
                           DailyItm.BatchNo,
                           IM.Name
                       };

        listItems.Add(new Items() { ItemMasterID = 0, Name = "Select One" });
        foreach (var lists in itemlist)
        {
            listItems.Add(new Items()
            {
                ItemMasterID = lists.ItemMasterID,
                BatchNo = lists.BatchNo,
                Name = lists.Name,                  
            });
        }

        itemlist = null;
        return listItems;
    }

【问题讨论】:

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


    【解决方案1】:

    一种可能的方法:

    Items selectedItem = (Items)lstItem.SelectedItem;
    int id = selectedItem.ItemMasterID;
    

    【讨论】:

      【解决方案2】:

      为了获得您必须在数据库中创建的 ID 号。

      例子

      SHOP_ID ='4987bc1b-c0a8-6cb7-12f4-0243011f7099' and (debitor_type is null or debitor_type in (CASE WHEN (select techfund_debitor_enabled from impl_shop where shop_id='4987bc1b-c0a8-6cb7-12f4-0243011f7099')

      【讨论】:

        猜你喜欢
        • 2013-09-14
        • 1970-01-01
        • 2015-03-22
        • 1970-01-01
        • 1970-01-01
        • 2015-08-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多