Tar*_*raW 4 c# mvvmcross xamarin windows-store-apps windows-8.1
在Windows 8.1中,当您添加基于Windows 8.1 Basic Page的View/Page时,它不再继承LayoutAware类,因为它在Win 8.1中不再存在.现在,所有基本页面都直接从Page类继承.此外,它不再具有OnNavigatedTo/OnNavigatedFrom事件,因为Win8.1 Basic页面现在利用NavigationHelper类并调用this.navigationHelper.LoadState和this.navigationHelper.SaveState事件处理程序.如果使用TipCalc示例并添加Windows Store基本页面,TipView,初始页面将如下所示:
public sealed partial class TipView : Page
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
/// <summary>
/// This can be changed to a strongly typed view model.
/// </summary>
public ObservableDictionary DefaultViewModel
{
get { return this.defaultViewModel; }
}
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
public TipView()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
}
Run Code Online (Sandbox Code Playgroud)
由于TipView页面现在直接从Page继承,如果您将TipView页面更改为继承自MvxStorePage,如下所示:
public sealed partial class TipView : MvxStorePage
{
private NavigationHelper navigationHelper;
private ObservableDictionary defaultViewModel = new ObservableDictionary();
Run Code Online (Sandbox Code Playgroud)
由于Page是部分类,因此会发生以下错误:
'TipCalc.CrossPlat.WinStore.Views.TipView'的部分声明不得指定不同的基类.
即使它允许将基类更改为MvxStorePage,也不能在LoadState事件处理程序中添加base.OnNavigatedTo(e),如下所示:
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
base.OnNavigatedTo(e);
}
Run Code Online (Sandbox Code Playgroud)
因为OnNavigatedTo中的e参数正在寻找NavigationEventArgs与LoadStateEventArgs.
任何帮助将不胜感激,因为我需要完成具有Windows 8.1实现的跨平台PCL项目.
我找到了如何在没有我在下面提到的黑客攻击的情况下解决这个问题的答案,但是黑客引导我找到答案.我发布的其他任何可能有问题的人想要添加一个继承自MvvmCross商店页面的Win8.1页面.
答案在于,在Page.xaml.cs中找到的Win8/Win8.1 Page类是一个部分类,它在CS和XAML中构建/包含整个完成的类定义,它们被共同编译以构建整个类对于页面.
因此,如果您有TipView页面,请通过更改代码更改从MvxStorePage继承的TipView页面,如下所示:
public sealed partial class TipView: MvxStorePage
Run Code Online (Sandbox Code Playgroud)
然后转到TipView页面XAML文件并更改默认根页面节点的声明:
<Page
x:Name="pageRoot"
x:Class="TipCalc.CrossPlat.WinStore.Views.TipView"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TipCalc.CrossPlat.WinStore.Views"
xmlns:common="using:TipCalc.CrossPlat.WinStore.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Run Code Online (Sandbox Code Playgroud)
要更改为以下页面节点声明并添加MvvmCross MvxStorePage命名空间,如下所示:
<StorePage:MvxStorePage
x:Name="pageRoot"
x:Class="TipCalc.CrossPlat.WinStore.Views.TipView"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TipCalc.CrossPlat.WinStore.Views"
xmlns:StorePage="using:Cirrious.MvvmCross.WindowsStore.Views"
xmlns:common="using:TipCalc.CrossPlat.WinStore.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Run Code Online (Sandbox Code Playgroud)
需要注意的关键事项:StorePage: MvxStorePage通过添加命名空间来引用StorePage命名空间Cirrious.MvvmCross.WindowsStore.Views,包括以下行:
xmlns:StorePage="using:Cirrious.MvvmCross.WindowsStore.Views"
Run Code Online (Sandbox Code Playgroud)
在XAML页面声明中.一旦我完成了这个,它就像一个魅力.
| 归档时间: |
|
| 查看次数: |
1682 次 |
| 最近记录: |