【发布时间】:2014-11-07 20:45:49
【问题描述】:
我在后面的代码中使用基本列表动态填充 ListPicker。在 SelectionChanged 事件中,我需要确定用户选择的项目的名称。目前我拥有的如下,但我无法获取项目的名称?
XAML
<toolkit:ListPicker x:Name="lp" Visibility="Collapsed"/>
XAML.CS
//Populate the ListPicker
List<ListPickerItem> l = new List<ListPickerItem>();
l.Add(new ListPickerItem { Name = "Flip_Vertical", Content = AppResources.App_Flip_Vertical });
l.Add(new ListPickerItem { Name = "Flip_Horizontal", Content = AppResources.App_Flip_Horizontal });
l.Add(new ListPickerItem { Name = "Flip_Both", Content = AppResources.App_Flip_Both });
lp.ItemsSource = l;
lp.Visibility = Visibility.Visible;
...
void lp_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (lp.SelectedIndex != -1)
{
var item = (sender as ListPicker).SelectedItem;
if (item != null)
{
//switch () //Need to determine the Name of the currently selected item?
}
}
}
编辑**
设置项目时无法调用名称
【问题讨论】:
标签: c# xaml windows-phone-8 listpicker