WP7如何给所有页面添加通用按钮?
在我的 WP7 应用程序中,每个页面的顶部都应该有一个“搜索”按钮。按下它时,应该打开搜索页面。
这怎么能做到呢?有没有一种方法可以在一个地方定义该按钮,或者我是否需要将“搜索”按钮添加到所有页面?
In my WP7 application, each page should have a Search button at the top. When pressing it, it should open the Search page.
How can this be done? Is there a way to define the button in one place, or do I need to add the Search button to all pages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
全局导航控件(这就是您所描述的)不符合符合 Metro 原则的应用程序的标准设计。有一些例外,但如果您想要这样做,因为这也是您在应用程序的 Android 和 iPhone 版本中所做的事情,那么我强烈建议您重新考虑应用程序的设计,使其符合标准该平台上的其他应用程序而不是其他平台上的您的应用程序。这样做将允许您创建一个看起来像属于该平台并且将按照用户期望运行的应用程序。
也就是说,有两种方法可以做到这一点。
首先,您可以将按钮添加到框架并在应用程序级别连接事件处理程序。
或者,您可以创建自己的基类,该基类继承自 ApplicationPage 并在各处包含您想要的按钮。然后,应用程序中的每个页面都应该从您自己的基页面继承。
我会选择第二个选项,因为我通常发现我希望所有页面都有自己的基类,以实现我不想重复的各种功能。
A global navigation control (which is what you are describing) does not fi within the standard design of an app conforming to the Metro principles. There are a couple of exceptions but as you're wanting do this because that's what you are also doing in the Android and iPhone versions of your app then I'd strongly recommend that you reconsider the design of the application so that it matches the stndards of other applications on the platform rather than your app on other platforms. Doing this will allow you to create an application which looks like it belongs on the platform and will behave as the user expects.
That said, there are 2 ways you could do this.
Firstly, you could add the button to the frame and wire up the event handler at application level.
Alternatively, you could create your own base class that inherits from ApplicationPage and contains the button you want everywhere. Each of the pages in your app should then inherit from your own base page.
I'd go for the second option as I usually find that I want my own base class for all pages for various pieces of functionality that I don't want to duplicate.