如何在 WP7 中以编程方式设置选定的全景项目

发布于 2024-10-11 06:01:32 字数 565 浏览 2 评论 0原文

我在 WP7 应用程序中使用全景控件。其中一个 PanoramaItems 将您带到另一个页面,然后您可以通过 EmailComposeTask 发送电子邮件。如果您没有选择发送电子邮件并按后退按钮,全景图将返回到您上次选择的项目。但是,如果您选择发送电子邮件(并因此离开应用程序),它不会返回到之前选择的 PanoramaItem。相反,它返回到全景图中的第一项。我尝试跟踪选定的索引并设置它,但收到一条错误消息,指出 SelectedIndex 不可设置。 MSDN 文档 http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.panorama.selectedindex%28VS.92%29.aspx

有没有办法手动设置选定的索引/项目在全景图上?如果没有,是否有办法让它记住所选择的内容,即使用户离开应用程序来撰写电子邮件?

I'm using a panorama control in a WP7 app. One of the PanoramaItems takes you to another page, which then allows you send an email through the EmailComposeTask. If you don't select to send the email and press the back button, the Panorama returns to the item you last selected. However, if you do select to send an email (and therefore leave the app), it does not return to the previously selected PanoramaItem. Instead, it returns to the first item in the Panorama. I tried keeping track of the selected index and setting it, but I got an error saying the SelectedIndex is not settable. This is confirmed on MSDN documentation http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.panorama.selectedindex%28VS.92%29.aspx

Is there any way to manually set the selected index/item on a panorama? If not, is there a way for it to remember what was selected, even if the user leaves the app to compose an email?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

爱格式化 2024-10-18 06:01:33

当设备进入横向视图时,我使用此模型更改为枢轴,我可能最终会将当前项目提取到应用程序状态。全景图是横向方向的禁忌。

private int hub_page_index;

protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
    base.OnOrientationChanged(e);

    if (panorama.Visibility == Visibility.Visible)
    {
        hub_page_index = panorama.SelectedIndex;
    }
    else if (pivot.Visibility == Visibility.Visible)
    {
        hub_page_index = pivot.SelectedIndex;
    }

    if (e.Orientation == PageOrientation.Landscape
     || e.Orientation == PageOrientation.LandscapeLeft
     || e.Orientation == PageOrientation.LandscapeRight)
    {
    // Display Pivot in Landscape orientation
        pivot.SetValue(Pivot.SelectedItemProperty, pivot.Items[panorama.SelectedIndex]);
        panorama.Visibility = Visibility.Collapsed;
        pivot.Visibility = Visibility.Visible;
    }
    else
    {
        // Display Panorama in Portrait orientation
        panorama.SetValue(Panorama.SelectedItemProperty, panorama.Items[pivot.SelectedIndex]);
        pivot.Visibility = Visibility.Collapsed;
        panorama.Visibility = Visibility.Visible;
    }
}

I'm using this model to change to a pivot when the device goes into landscape view, I'll probably end up extracting the current item to the application state. The panorama is a no-go in landscape orientation.

private int hub_page_index;

protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
    base.OnOrientationChanged(e);

    if (panorama.Visibility == Visibility.Visible)
    {
        hub_page_index = panorama.SelectedIndex;
    }
    else if (pivot.Visibility == Visibility.Visible)
    {
        hub_page_index = pivot.SelectedIndex;
    }

    if (e.Orientation == PageOrientation.Landscape
     || e.Orientation == PageOrientation.LandscapeLeft
     || e.Orientation == PageOrientation.LandscapeRight)
    {
    // Display Pivot in Landscape orientation
        pivot.SetValue(Pivot.SelectedItemProperty, pivot.Items[panorama.SelectedIndex]);
        panorama.Visibility = Visibility.Collapsed;
        pivot.Visibility = Visibility.Visible;
    }
    else
    {
        // Display Panorama in Portrait orientation
        panorama.SetValue(Panorama.SelectedItemProperty, panorama.Items[pivot.SelectedIndex]);
        pivot.Visibility = Visibility.Collapsed;
        panorama.Visibility = Visibility.Visible;
    }
}
吲‖鸣 2024-10-18 06:01:32

我不确定您是否可以以编程方式将动画强制到另一个 PanoramaItem,但您可以更改 Panorama.DefaultItem

因此,您可能有 3 个 PanoramaItem,并且在 OnNavieratedTo() 处理程序上,通过以下方式更改默认项目:

panoramaControl.DefaultItem = panoramaControl.Items[indexToSet];

这在您从逻辑删除中恢复时应该会有所帮助。

I'm not sure if you can programmatically force an animation to another PanoramaItem, but you can change the Panorama.DefaultItem.

So you might have 3 PanoramaItem's and on the OnNavigatedTo() handler, change the default item via:

panoramaControl.DefaultItem = panoramaControl.Items[indexToSet];

This should help when you recover from a tombstone.

友欢 2024-10-18 06:01:32

您可以尝试 Silicon Shark 在该帖子中发布的解决方案。值得注意的是,它可以工作,但仅限于初始显示 - 这对于您在逻辑删除后恢复状态的要求来说应该不是问题。

如何以编程方式设置可见项目在全景控件中?

您可以从全景的 SelectedIndex 属性获取当前活动页面。

不幸的是,设置 DefualtItem 只是解决此问题的近似方法,您可能已经发现了这一点。

编辑:请注意,设置 DefaultItem 会更改全景图中的第一页。这是一个微妙的差异,但您会通过查看标题的位置和背景图像的环绕来了解它的重要性。

You could try the solution posted by Silicon Shark in this thread. It's noted to work, but only on the initial display - which shouldn't be a problem for your requirements of restoring state after tombstoning.

How to programmatically set the visible item in a Panorama control?

You can get the currently active page from the panorama's SelectedIndex property.

Unfortunately setting DefualtItem is only an approximation to solving this problem, which you may have discovered already.

Edit: Be aware that setting DefaultItem, changes which page of the panorama is the first page. It's a subtle difference, but you will see how it matters looking at the positioning of the heading and the wrap around of the background image.

心凉怎暖 2024-10-18 06:01:32

这是一个解决方案。它确实按预期工作,并且不会重新排列您的全景图,因此您的用户界面是一致的。

pan.SetValue(Panorama.SelectedItemProperty, panoramaItem);
Panorama temp = pan;
LayoutRoot.Children.Remove(pan);
LayoutRoot.Children.Add(temp);
LayoutRoot.UpdateLayout();

这不是一个完美的解决方案,因为它不像全景图那样很好地滑动,而且可能不是很有效,但另一方面,您没有更改默认项目,因此您的用户界面保持一致。

Here is a solution. It does work as expected and does not rearrange your panorama, so your user interface is consistent.

pan.SetValue(Panorama.SelectedItemProperty, panoramaItem);
Panorama temp = pan;
LayoutRoot.Children.Remove(pan);
LayoutRoot.Children.Add(temp);
LayoutRoot.UpdateLayout();

this is not a perfect solution in that it does not slide nicely like panorama should, and it is probably not very efficient, but on the other hand you are not changing the default item so your user interface stays consistent.

鸠魁 2024-10-18 06:01:32

我测试了此处列出的解决方案,但没有成功。这就是我所做的,这就像一个魅力!

PanoramaItem panItem = (PanoramaItem)panorama.Items[1];

panorama.Items.Remove(panItem);

panorama.Items.Insert(0, panItem);

您需要从列表中删除面板并将其重新插入到所需位置!

I tested solutions listed here without success. Here is what I did that works like a charm!

PanoramaItem panItem = (PanoramaItem)panorama.Items[1];

panorama.Items.Remove(panItem);

panorama.Items.Insert(0, panItem);

You need to remove the panel from the list and re-inserting it at the desired position!

夏末 2024-10-18 06:01:32

设置新的所选项目但是

pan.SetValue(Panorama.SelectedItemProperty, pan.Items[newSelectedItem]);

,它仅适用于初始项目,因此我的想法是当我们更改所选项目时让全景控件重新初始化。这是我的代码,只需在 Panorama.SelectedItem 更改后添加此代码即可。

(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Collapsed;
pan.SetValue(Panorama.SelectedItemProperty, pan.Items[(curIndex + 1) % pan.Items.Count]);
pan.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Visible;

但现在没有过渡效果!虽然,你可以创造你自己。

它对我来说非常有用,该页面还创建了向右滑动的效果 http: //xme.im/slide-or-change-panorama-selected-item-programatically

Set new selected item by

pan.SetValue(Panorama.SelectedItemProperty, pan.Items[newSelectedItem]);

However, it work only on the initial so my idea is let the panorama control re-init when we change the selected item. This is my code, just add this after Panorama.SelectedItem changing.

(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Collapsed;
pan.SetValue(Panorama.SelectedItemProperty, pan.Items[(curIndex + 1) % pan.Items.Count]);
pan.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Visible;

But there is not transition effect now! Although, you can create your self.

It work great for me, this page also create a effect for sliding right http://xme.im/slide-or-change-panorama-selected-item-programatically

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文