gpt4 book ai didi

c# - 如何获取 ListPicker 的选中项

转载 作者:行者123 更新时间:2023-11-30 13:26:36 24 4
gpt4 key购买 nike

我想确定当前在 ListPicker 中选择的项目的名称。我不确定如何在 SelectionChanged 事件中获取项目的名称。

XAML

<Grid.Resources>
<DataTemplate x:Name="PickerItemTemplate">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</Grid.Resources>

<toolkit:ListPicker x:Name="ThemeListPicker" Header="{Binding Path=LocalizedResources.SettingsPage_ThemeListPicker_Header, Source={StaticResource LocalizedStrings}}"
ItemTemplate="{StaticResource PickerItemTemplate}"
SelectionChanged="ThemeListPicker_SelectionChanged"/>

XAML.CS

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

themeList = new List<Theme>();
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;

关于c# - 如何获取 ListPicker 的选中项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20591841/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com