问题描述
我有两个 ListBox
项目:一个用于显示所有项目,另一个 ListBox
用于仅显示选定的项目,现在当我使用硬件后退按钮时,第二个 ListBox
项目没有显示?
I have two ListBox
items: one for show all items and another ListBox
for show only selected item and now when I am using hardware back button second ListBox
item is not showing?
我需要做什么才能让 ListBox
在返回时可以选择/点击?
What do I need to do to allow the ListBox
to be selectable/clickable upon return?
Height="72" TextWrapping="Wrap" Name="txtMSG" Text="TextBox" Width="456"/>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="2" Margin="15,10,15,0">
<ListBox Name="list_location" Tap="list_location_Tap" Foreground="Black">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="item_name" Text="{Binding description, Mode=OneWay}" Padding="5,15,5,15" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeLarge}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Name="list_locationAdd" Foreground="Black" Visibility="Collapsed">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="item_name" Text="{Binding description, Mode=OneWay}" Padding="5,15,5,15" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeLarge}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
list_locationAdd.Visibility = Visibility.Visible;
list_location.Visibility = Visibility.Collapsed;
if (!list_locationAdd.Items.Contains(list_location.SelectedItem))
{
list_locationAdd.Items.Add(list_location.SelectedItem);
}
推荐答案
使用 StorageFile 类创建 XML 文档并将其保存到您的手机.每次打开应用程序时,它都会在启动时检查您的 xml 文件并填充数据网格.因此,当您对列表框进行更改时,它也应该对 xml 文件进行更改.下次退出应用程序并再次启动它时,从 xml 文件中读取数据,然后它具有上次的数据.所以我的答案是:使用 xml 文件将您的数据保存在手机上.
Create XML document and save it to your phone using StorageFile class. Everytime you open your app, it will on launch check your xml file and populate the datagrid. So when you make changes to listboxes it should make changes to xml file too. Next time you quit your application and launch it again, reads data from xml file and then it has the data as it was last time. So my answer is: save your data on phone with xml file.
将数据保存到手机:https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.aspx
处理 XML 文档和元素:https://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument%28v=vs.110%29.aspx
Handling XML documents and elements: https://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument%28v=vs.110%29.aspx
这篇关于WP8 使用硬件后退按钮后无法显示列表框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!