WP8如何创建基本网页&放大器;用它 [英] WP8 how to create base-page & use it

查看:197
本文介绍了WP8如何创建基本网页&放大器;用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我GOOGLE了,但没有得到任何有用的资源,所以我决定问

I've googled, but did not get any useful resources, so i decided to ask.

问题:

我有一个 的Windows Phone 8的C#/ XAML .NET 4.5应用程序,也就是将有多个页面( 15 - 50 的),它们的都将有相似的外观+相同的DataContext设置为视图模型的一个实例:

I have a Windows Phone 8 C#/XAML .NET 4.5 Application, that is going to have several pages (15 - 50) that are all going to have similar look + same datacontext set to one instance of ViewModel:

    --------------------------
    |logo         usermenu(v)|
    --------------------------
    |                        |
    |                        |
    |                        |
    |     ..variable..       |
    |     ..content...       |
    |                        |
    |                        |
    --------------------------

问:

我找不到任何在这个问题上使用,可能有人解释如何做它

I can't find anything usable in this matter, could someone explain how to do it?

(我是一个新秀 - 这意味着我是傻瓜的解释感谢任何有用的信息,但更)?


  • 如何建立一个基地页/祖先来自哪里?

  • How to create a base-page/ancestor to derive my pages from?

有没有办法来设置的祖先一个DataContext?

Is there a way to set a datacontext in ancestor?

如何使用该基地页/祖先?

How to use that base-page/ancestor?

PS:如果你想知道为什么我想有相同的datacontext的网页,在有更写它这个问题我之前

P.S.: In case you're wondering why I want to have pages with same datacontext, there is more written about it in This question I asked before

推荐答案

这听起来像你可能在这里采取错误的做法。

It sounds like your probably taking the wrong approach here.

而不是有15-50使用相同的数据背景相同的页面,有一个页面,改变的DataContext。这将是比有很多,所有来自同一基地降落的网页要简单得多。结果
这是当然的,这取决于你的实际内容如何变量。

Rather than have 15-50 identical pages with the same data context, have one page and vary the DataContext. This will be much simpler than having lots of pages which all descend from the same base.
This is, of course, dependent upon how variable your actual content is.

在您的具体问题方面:


  • 页是类像任何其他,因此继承了定义同样的方式。只要确保你指定在 CS XAML的祖先文件。

您不能设置的DataContext的祖先是实际情况不同,如果你只是把它的祖先也不会提供给该实例。您需要设置的DataContext在实例

You can't set the datacontext in the ancestor to be different to the actual instance and if you just set it in the ancestor it won't be available to the instance. You need to set the DataContext in the instance.

事情是这样的:

基页

namespace SO19398590
{
    using Microsoft.Phone.Controls;

    public class MyBasePage : PhoneApplicationPage
    {
    }
}

从这个继承了一个实际的页面结果
CS:

An actual page that inherits from this.
cs:

public partial class MainPage : MyBasePage
{
    public MainPage()
    {
        InitializeComponent();
    }
}



XAML(部分):

xaml (partial):

<so19398590:MyBasePage
    x:Class="SO19398590.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:so19398590="clr-namespace:SO19398590"
    SupportedOrientations="Portrait">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <!-- put stuff here -->
   </Grid>

</so19398590:MyBasePage>

请注意,这是一个没有视觉效果的基础页,我知道你问的可视化继承基类。结果
不幸的是一个非常贫穷的故事,随着Windows Phone,当涉及到可视化页面继承。该工具(设计者)不喜欢它,它很容易进入那些尴尬诊断的问题。

Note that this is a base page with no visuals and I am aware that you asked for visual inheritance from the base class.
Unfortunately there is a very poor story with Windows Phone when it comes to visual page inheritance. The tooling (designers) doesn't like it and it's very easy to get into problems that are awkward to diagnose.

有一个更好的办法是使用[多个实例]一个页面加载,但根据您要显示的数据不同的用户控件。结果
稍微复杂一点的选择,但它仍允许一个标准的网页浏览体验是使用自定义的 PhoneApplicationFrame ,包括有共同的UI元素。

A better approach would be to use [multiple instances of] one page but load different user controls depending on the data you want to display.
A slightly more complicated alternative but which still allows for a standard page navigation experience is to use a custom PhoneApplicationFrame and include the common UI elements there.

很抱歉,这是一个相当通用的答案,但最好的解决方案,将取决于究竟是怎样要在你定义为可变内容的空间。

Sorry this is quite a generic answer but the "best" solution will depend on what is actually going in the space you define as "variable content".

这篇关于WP8如何创建基本网页&放大器;用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆