![](/img/trans.png)
[英]LongListSelector C# - How to get SelectedItem as string from grouped data list - Windows Phone Silverlight 8.1
[英]How to get the selecteditem from a listpicker as string in c# for windows phone application
這是我的XAML代碼
<toolkit:ListPicker SelectionChanged="CountryLP_SelectionChanged" Header="--Select Mode--" ItemsSource="{Binding CountryListdata, ElementName=this}" x:Name="CountryLP" VerticalAlignment="Center">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate >
<StackPanel>
<TextBlock Text="{Binding country}" />
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate >
<StackPanel>
<TextBlock Text="{Binding country}" />
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
在頁面加載期間,控件自動轉到事件CountryLP_SelectionChanged,我想獲取選定的項目字符串
這是ac#代碼,用於將Values設置為listpicker
//to get values from webservice
public class CountryList
{
public String id{ get; set; }
public String country{ get; set; }
}
private void CountryLP_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (CountryLP.SelectedItem == null)
return;
//var s= (sender as ListPicker).SelectedItem;
CountryList s= CountryLP.SelectedItem as CountryList;
//string s= CountryLP.SelectedItem as string;
//string s= CountryLP.SelectedItem.toString();
System.Diagnostics.Debug.WriteLine(s);
}
我嘗試了幾種方法,但是沒有得到字符串值。 誰能幫我這個?
代碼看起來不錯。 您可以通過將其添加到配置文件中來處理此異常。
<configuration>
<runtime>
<legacyCorruptedStateExceptionsPolicy enabled="true" />
</runtime>
</configuration>
也試試
var content = ((ListPickerItem)CountryLP.SelectedItem).Content;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.