WP8 Can't show listbox item after using hardware back button

末鹿安然 提交于 2020-01-16 11:14:07

问题


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?

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);

}

回答1:


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.

Save data to phone: https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.aspx

Handling XML documents and elements: https://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument%28v=vs.110%29.aspx



来源:https://stackoverflow.com/questions/29844360/wp8-cant-show-listbox-item-after-using-hardware-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!