WPF 框架源刷新加载的页面
我遇到过一个奇怪的场景,框架拒绝刷新其内容。
我可以理解发生了什么,但我没有找到解决方案。
我有一个页面,其中有一个框架 (Frame1) 和几个按钮。 当我单击按钮时,页面就会加载到框架中。 这在大多数情况下都非常有效。
Private Sub btnIncidents_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnIncidents.Click
Frame1.Source = New System.Uri("/Incident/Incidents.xaml", UriKind.Relative)
End Sub
但是,我遇到了一种情况,我需要选择之前单击的按钮才能有效地对 Uri 进行刷新。 问题是它什么也没做,因为 Uri 没有改变。 这是有道理的,但这不是我想要的,我需要再次调用它。
我的第一个解决方案是引入 Frame1.Refresh,它最初起到了作用。 但是,一旦刷新页面,所有按钮都无法加载不同的页面。
就好像通过调用 Frame1.Refresh 我破坏了 Frames 导航到其他页面的能力。
我的第二个想法是将 Frame 源设置为 Nothing(Null),然后将源设置为 URI,但这也不起作用。 即 Frame1.Source = Nothing
还有其他人遇到过这个或可能有一些建议吗? 我只需要刷新/重新加载框架页面而不破坏框架!
I've come across a strange scenario where a frame refuses to refresh its content.
I can kinda understand what's happening but the solution is not coming to me.
I have a page that has a frame (Frame1) and several buttons. When I click on a button a page is loaded into the frame. This works perfectly in most situations.
Private Sub btnIncidents_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnIncidents.Click
Frame1.Source = New System.Uri("/Incident/Incidents.xaml", UriKind.Relative)
End Sub
However, I have a situation where I need to select the button that was previously clicked to effectively do a Refresh on the Uri. The problem is it simply does nothing because the Uri hasn't changed. That makes sense but it's not what I want, I need to call it again.
My first solution was to introduce Frame1.Refresh which initially did the trick. But once a page was Refreshed, none of the Buttons could load a different page.
It was as if by calling Frame1.Refresh I'd broken the Frames ability to navigate to other pages.
My second idea was to set the Frame source to Nothing (Null) and then set the source to the URI but that didn't work either. ie Frame1.Source = Nothing
Has anyone else come across this or maybe have some suggestions? I just need to Refresh/Reload the Frames page without breaking the Frame!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也有类似的问题 - 不过 html 。 显然会清除导航历史记录来解决它
,但就我而言,我并不关心。
从 http:/ 得到答案/social.msdn.microsoft.com/Forums/en-US/wpf/thread/8fc6bd83-2803-4820-a22b-d4d87638c4e2
I had the similar problem - with html though. Resolved it with
apparently will clear navigation history, but in my case I do not really care.
Got the answer from http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/8fc6bd83-2803-4820-a22b-d4d87638c4e2
我知道这已经很旧了,但我也遇到了同样的问题。 我已将框架的源绑定到视图模型中的属性,当单击菜单项时,它将重新设置指定源的属性,从而导致发生导航。 问题是两个子菜单项访问了相同的 URI 源(该页面将在构造函数中调用时重新加载以获取更新的数据)。 URI 未更改的事实导致页面无法重新加载。 我的简单技巧是包含两个调用之间不同的查询字符串。 所以第一个 URI 看起来像:
第二个像:
SomePage.xaml?UserControl=2
我知道这是“hacky”并且远非完美,但我毕竟是新手,它适用于我。 在我弄清楚这一点之前,我花了两天的时间把头撞在墙上并咒骂流行的搜索引擎,所以希望它可以帮助其他人。
I know this is old, but I had this same problem. I had bound the frame's source to a property in the viewmodel and when a menu item was clicked, it would re set the property that specified the source, causing navigation to occur. The problem was two sub menu items hit the same URI source (the page was to reload on a call in the constructor to fetch updated data). The fact that the URI was unchanged caused the page not to reload. My simple hack was to include a query string that differed between the two calls. So the first URI would look like:
and the second like:
SomePage.xaml?UserControl=2
I know this is "hacky" and far from perfect but I am a newbie after all, and it worked for me. I spent two days banging my head against the wall and cursing out popular search engines before I figured this out so hopefully it can help someone else.