Csharp/C#教程:如何获取ListPicker的选定项目分享


如何获取ListPicker的选定项目

我想确定当前在ListPicker中选择的项目的名称。 我不确定在SelectionChanged事件中要做什么来获取项目的名称。

XAML

      

XAML.CS

 protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); themeList = new List(); themeList.Add(new Theme() { Name = "light" }); themeList.Add(new Theme() { Name = "dark" }); ThemeListPicker.ItemsSource = themeList; } private void ThemeListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e) { //get the name of the current item in the listpicker? } 

 var item = (sender as ListPicker).SelectedItem; 

可能是这样的。

 Theme selectedObj = ThemeListPicker.SelectedItem as Theme; 

这是你可以帮助你的解决方案。

上述就是C#学习教程:如何获取ListPicker的选定项目分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

  private void ThemeListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e) { //get the name of the current item in the listpicker? string currentItemName =string.Empty; Theme theme= (sender as ListPicker).SelectedItem as Theme; if(theme!=null) { currentItemName = item.Name; } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1008522.html

(0)
上一篇 2021年12月29日
下一篇 2021年12月29日

精彩推荐