WP7 中的绑定 Panorama.SelectedIndexProperty

发布于 2024-10-15 03:03:49 字数 428 浏览 4 评论 0原文

首先,SelectedIndex 没有在标记中公开,因此您必须在后面的代码中执行此操作,对吗?

其次,我在后面的代码中设置了绑定:

Binding binding = new Binding("Main.PanoSelectedIndex.ObservedObject");
binding.Mode = BindingMode.TwoWay;
rootPano.SetBinding(Panorama.SelectedIndexProperty, binding);`

(ObservedObject 实现 iNotifyChanged)

绑定路径指向我的主视图模型,我可以看到 PanoramaItem 正在更新绑定。但是,当其他内容(MVVM Light 命令)更改绑定时,全景图不会响应。有什么想法吗?

谢谢, 罗杰

First, SelectedIndex is not exposed in markup, so you have to do it in code behind, right?

Second, I have set the binding in code behind:

Binding binding = new Binding("Main.PanoSelectedIndex.ObservedObject");
binding.Mode = BindingMode.TwoWay;
rootPano.SetBinding(Panorama.SelectedIndexProperty, binding);`

(ObservedObject implements iNotifyChanged)

The binding path points to my Main view model, and I can see that the PanoramaItem is updating the binding. However,the panorama does not respond when something else (a MVVM Light command) changes the binding. Any ideas?

Thanks,
Roger

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

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

发布评论

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

评论(2

迷途知返 2024-10-22 03:03:49

引用Windows Phone 开发人员常见问题解答

全景图的设计是为了让用户能够控制,因此您无法以编程方式设置 SelectedIndex,或强制导航到全景图项目。

您可以设置 DefaultItem,以便在首次启动全景图时,全景图导航到该项目,但您无法以编程方式导航到该项目之外。还可以使用 DefaultItem,以便后退导航感觉用户所在的项目没有更改。

更新:您可以使用 DefaultItem 保存/恢复 Panorama 的选择,如下所示(代码来自 Jeff Prosise 的 最近的博客文章) :

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
 // Save the Panorama control's SelectedIndex in page state
 State["Index"] = PanoramaControl.SelectedIndex;
}
 
protected override void OnNavigatedTo(NavigationEventArgs e)
{
 // Restore the Panorama control's SelectedIndex
 if (State.ContainsKey("Index"))
 PanoramaControl.DefaultItem = PanoramaControl.Items[(int)State["Index"]];
}

To quote from the Windows Phone Developer FAQ

Panorama is designed so the user is in control, there fore you cannot set SelectedIndex programmatically, or force a navigation to a panorama item.

You can set the DefaultItem so that when your panorama is first launched, the panorama navigates to that item, but you can’t navigate programmatically beyond that. DefaultItem can also be used so that a back navigation feels like the item where the user was at did not change.

UPDATE: You can use the DefaultItem to save/restore the selection for a Panorama as shown below (code from Jeff Prosise's recent blog post):

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
 // Save the Panorama control's SelectedIndex in page state
 State["Index"] = PanoramaControl.SelectedIndex;
}
 
protected override void OnNavigatedTo(NavigationEventArgs e)
{
 // Restore the Panorama control's SelectedIndex
 if (State.ContainsKey("Index"))
 PanoramaControl.DefaultItem = PanoramaControl.Items[(int)State["Index"]];
}
盗心人 2024-10-22 03:03:49

据我所知 SelectedIndex 是 Panorama 中的只读属性(奇怪为什么 WP7 SDK 将其设为只读)。因此,您只能将 UI 更改返回到 VM,并且无法通过 VM propertychange 更新 UI。

DefaultItem 是用于以编程方式设置索引的属性。

同样,以编程方式设置已实例化的全景的问题是,标题和全景项目的对齐不会同步。无论如何,我并不劝阻,但仍然有一些被黑客攻击的机会。

As far as I know SelectedIndex is a readonly property in Panorama ( Weired why WP7 SDK made it readonly). So you will get only UI change back to your VM, and you cant update UI through the VM propertychange.

And DefaultItem is the property which used to set the index programatically.

Again the issue of programatically setting an already instantiated Panorama is that, the alignment of the Title and Panoramaitem wont be in sync. Anyway I am not discouraging but there is still some chance of hack there.

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