首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WP7逻辑删除-简单的实践

WP7逻辑删除-简单的实践
EN

Stack Overflow用户
提问于 2011-07-17 06:23:50
回答 1查看 350关注 0票数 0

我有一个数据绑定的xml阅读器。MainPage连接到DetailsPage:当用户点击主页中的姓名时,她会获得该姓名的详细信息(年龄、性别、出生日期等)。在DetailsPage中。

我遇到了盗用自动取款机的麻烦。当我点击窗口按钮,然后点击后退按钮,我进入一个空的DetailsPage。

解决这个问题的最简单方法是什么?我尝试使用TombstoneHelper,但它也显示为空页面。

DetailsPage.xaml

代码语言:javascript
复制
        <controls:PanoramaItem Header="" Margin="0,0,0,80">
            <ScrollViewer>
                <StackPanel>
                    <TextBlock TextWrapping="Wrap" Width="432" Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="0,0,0,10" d:LayoutOverrides="Width" Foreground="#DEFFFFFF"><Run Text="Personal D"/><Run Text="e"/><Run Text="tails"/></TextBlock>
                    <StackPanel HorizontalAlignment="Left" Width="432" Orientation="Horizontal">
                        <TextBlock TextWrapping="Wrap" Margin="20,0,7,0" Foreground="#DEFFFFFF"><Run Text="Name"/><Run Text=":"/></TextBlock>
                        <TextBlock x:Name="username" TextWrapping="Wrap" Text="{Binding Name}" Foreground="#DEFFFFFF" />
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Left" Width="432" Orientation="Horizontal">
                        <TextBlock TextWrapping="Wrap" Margin="20,0,7,0" Foreground="#DEFFFFFF"><Run Text="Age"/><Run Text=":"/></TextBlock>
                        <TextBlock x:Name="age" TextWrapping="Wrap" Text="{Binding Age}" Foreground="#DEFFFFFF"/>
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Left" Width="432" Orientation="Horizontal">
                        <TextBlock TextWrapping="Wrap" Margin="20,0,7,0" Foreground="#DEFFFFFF"><Run Text="Nationality"/><Run Text=":"/></TextBlock>
                        <TextBlock x:Name="country" TextWrapping="Wrap" Text="{Binding Country}" Foreground="#DEFFFFFF"/>
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Left" Width="432" Orientation="Horizontal">
                        <TextBlock TextWrapping="Wrap" Margin="20,0,7,0" Foreground="#DEFFFFFF"><Run Text="Country of Birth"/><Run Text=":"/></TextBlock>
                        <TextBlock x:Name="cobirth" TextWrapping="Wrap" Text="{Binding Cobirth}" Foreground="#DEFFFFFF"/>
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Left" Width="432" Orientation="Horizontal">
                        <TextBlock TextWrapping="Wrap" Margin="20,0,7,0" Foreground="#DEFFFFFF"><Run Text="Place of Birth"/><Run Text=":"/></TextBlock>
                        <TextBlock x:Name="fobirth" TextWrapping="Wrap" Text="{Binding Pobirth}" Foreground="#DEFFFFFF"/>
                    </StackPanel>
                </StackPanel>
            </ScrollViewer>
        </controls:PanoramaItem>

DetailsPage.cs

使用TombstoneHelper;

代码语言:javascript
复制
    public User()
    {
        InitializeComponent();
        SupportedOrientations = SupportedPageOrientation.Portrait;
    }
    protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedFrom(e);

        this.SaveState();  // <- first line
    }

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

        this.RestoreState();  // <- second line
    }

Mainpage.Cs

代码语言:javascript
复制
    private void UserListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.AddedItems.Count > 0)
        {
            NavigationService.Navigate(new Uri("/DetailsPage.xaml", UriKind.Relative));

            FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
            root.DataContext = (RosterItem)e.AddedItems[0];
            ((ListBox)sender).SelectedIndex = -1;

        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-17 07:20:43

在所有条件都相同的情况下,Tombstone helper应该可以正常工作。请记住,您需要为Tombstone帮助器命名控件(使用x:Name属性)才能访问它们。还要确保在NavigatedFrom()方法中调用SaveState(),在NavigatedTo()中调用RestoreState() (而不是反过来)。

如果不是这样,那么一定是代码中的其他地方出了问题。如果您发布代码的相关部分,我们可能会有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6720638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档