gpt4 book ai didi

windows-phone-7 - 获取 ListPicker 中选定项的值

转载 作者:行者123 更新时间:2023-12-01 23:45:07 27 4
gpt4 key购买 nike

我有一个显示项目名称的列表选择器。选择项目时,我想获取该选定项目的项目 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# 代码中,我将两者都绑定(bind)到列表选择器。我将此数据直接绑定(bind)到列表选择器。

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

最佳答案

一种可能的方式:

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

关于windows-phone-7 - 获取 ListPicker 中选定项的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29690487/

27 4 0