我想将列表的特定项添加到longlistselector列表中。 我想它应该像这样工作,对吗?
代码在这里:
所以首先我得到一个json响应并填写一个临时列表(它用于建议箱 - 我删除了其余的但我的建议箱工作得很好)
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Result))
{
wc.DownloadStringCompleted -= wc_DownloadStringCompleted;
last_points_list_all = new List<string>();
last_points_list_all.Clear();
var root = JsonConvert.DeserializeObject<RootObject>(e.Result);
var test = root.results;
foreach (var rs in test.items)
{
last_points_list_all.Add(rs.title);
}
}
}
这里我想把我的字符串列表项放入一个可观察的列表中,该列表显示为longlistselector(我希望“保存”我在longlistselector中最后选择的建议框项目)
private void selectitem(object sender, System.Windows.Input.GestureEventArgs e)
{
ObservableCollection<myList> last_points_list = new ObservableCollection<myList>();
last_points_list.Add(new myList(last_points_list_all[Suggestion_listbox.SelectedIndex]));
}
这是我的班级
public class myList
{
public string Last_Points_Name
{
get;
set;
}
public myList(string last_points_name)
{
this.Last_Points_Name = last_points_name;
}
}
和xaml(我猜xaml不是很“干净”......必须弄清楚我不需要的东西......问题可能在这里吗?
<phone:LongListSelector
x:Name="listsector"
HorizontalAlignment="Left"
Height="440"
VerticalAlignment="Top"
SelectionChanged="Last_Point_Tap"
LayoutMode="List"
IsGroupingEnabled="False"
Width="456">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Top" HorizontalAlignment="Left">
<Grid Height="100" >
<TextBlock FontWeight="Bold"
Tap="Last_Point_Tap"
Text="{Binding Last_Points_Name}"
FontSize="48"
Margin="20,0,0,0"
Height="70"
VerticalAlignment="Bottom"/>
</Grid>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
提前致谢