WPF 框架导航
我对 WPF 还很陌生,并通过 MVVM 实现它,并且我正在尝试开发一个没有代码隐藏的应用程序,以帮助打破我对 UI 设计的固有思维方式。无论如何,重点是:在我的 XAML 中,我有一个窗口,其中包含一个框架,该框架将托管我在单独的 xaml 文件中创建的各种页面。我想要框架将托管的各个页面中包含的按钮,以方便框架的导航。我意识到我可以将按钮放在窗口上,但这不是我想要的;我需要它们在框架当时恰好指向的任何页面中。我认为这可行:
<Button Style="{StaticResource NavigationButton}" Content="Design" Grid.Row="0" Grid.Column="0" Command="NavigationCommands.GoToPage" CommandParameter="DesignMenu.xaml" />
但按钮呈灰色:( 我认为由于页面托管在框架内,并且由于框架可以处理导航命令,因此该命令会神奇地冒泡,最终到达框架,并且框架的源属性将更改为 designmenu.xaml?我还尝试通过引用框架的名称来指定命令的目标,但页面不会“看到”框架,因为它们位于单独的文件中,因此不会工作欢迎任何见解或最佳实践。
I'm pretty new to WPF and implementing it via MVVM, and I'm trying to develop an application with no code-behind to help break my hold ways of thinking about UI design. Anyways, to the point: In my XAML, I have a Window which contains a Frame which will host various pages that I've created in seperate xaml files. I'd like for the buttons contained in the various pages that the frame will host to facilitate the frame's navigation. I realize I could put the buttons on the window, but that's not what I'm going for here; I need them in whatever page the frame happens to be pointing to at the time. I thought that this would work:
<Button Style="{StaticResource NavigationButton}" Content="Design" Grid.Row="0" Grid.Column="0" Command="NavigationCommands.GoToPage" CommandParameter="DesignMenu.xaml" />
but the button is grayed out :( I figured that since the page was hosted within the frame, and that because frames can handle navigation commands, that the command would magically bubble up, get to the frame eventually, and the frame's source attribute would change to designmenu.xaml? I also tried specifying a target for the command by referencing the frame's name, but the page doesn't "See" the frame since they're in separate files, so that doesn't work either. Any insights or best practices are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果有人好奇的话,经过几天的头撞桌子后,我发现超链接对象正是我在这里寻找的东西。只需将其打扮得像一颗纽扣即可,瞧。此 MSDN 概述有所帮助: MSDN WPF 导航概述
Well, if anyone was curious, after days of beating my head against a desk, I discovered that a Hyperlink object does exactly what I'm looking for here. It's just a matter of dressing it up to look like a button, and voila. This MSDN Overview helped: MSDN WPF Navigation Overview