Permalink
Browse files

WinRT Samples up and running :) although it may take some building to…

… get them to run - sorry gitignore issues on include paths :/
  • Loading branch information...
1 parent f8370ce commit 52b71f23990a1d80f916d5af6b9ba2247858827b @slodge slodge committed Mar 28, 2012
@@ -227,6 +227,7 @@
<Compile Include="ViewModels\MvxViewModel.cs" />
<Compile Include="Views\MvxShowViewModelRequest.cs" />
<Compile Include="Views\MvxViewsContainer.cs" />
+ <Compile Include="WinRT\Interfaces\IMvxWinRTViewPresenter.cs" />
<Compile Include="WinRT\Platform\MvxBaseWinRTSetup.cs" />
<Compile Include="WinRT\Platform\MvxDebugTrace.cs" />
<Compile Include="WinRT\Platform\MvxStorageFileStoreService.cs" />
@@ -237,6 +238,8 @@
<Compile Include="WinRT\Views\MvxWinRTExtensionMethods.cs" />
<Compile Include="WinRT\Views\MvxWinRTPage.cs" />
<Compile Include="WinRT\Views\MvxWinRTViewDispatcher.cs" />
+ <Compile Include="WinRT\Views\MvxWinRTViewDispatcherProvider.cs" />
+ <Compile Include="WinRT\Views\MvxWinRTViewPresenter.cs" />
<Compile Include="WinRT\Views\MvxWinRTViewsContainer.cs" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' ">
@@ -45,7 +45,13 @@ public static void ClearAllSingletons()
{
lock(Singletons)
{
- Singletons.ForEach(s => s.Dispose());
+ foreach (var s in Singletons)
+ {
+ // note that linq is not used because of winrt!
+ // Singletons.ForEach(s => s.Dispose());
+ s.Dispose();
+ }
+
Singletons.Clear();
}
}
@@ -10,6 +10,7 @@
#endregion
using System;
+using System.Reflection;
using Cirrious.MvvmCross.Interfaces.ViewModels;
using Cirrious.MvvmCross.Interfaces.Views;
@@ -66,16 +67,41 @@ private static bool TryUnregisterView<T>(this IMvxView<T> view)
return true;
}
+#if NETFX_CORE
+ public static PropertyInfo RecursiveGetDeclaredProperty(this TypeInfo type, string name)
+ {
+ var candidate = type.GetDeclaredProperty(name);
+ if (candidate != null)
+ return candidate;
+
+ var baseType = type.BaseType;
+ if (baseType != null)
+ return RecursiveGetDeclaredProperty(baseType.GetTypeInfo(), name);
+
+ return null;
+ }
+#endif
+
public static IMvxViewModel ReflectionGetViewModel(this IMvxView view)
{
if (view == null)
return null;
+#if NETFX_CORE
+ var propertyInfo = view.GetType().GetTypeInfo().RecursiveGetDeclaredProperty("ViewModel");
+
+ if (propertyInfo == null)
+ return null;
+
+ return (IMvxViewModel)propertyInfo.GetValue(view, new object[] { });
+#else
var propertyInfo = view.GetType().GetProperty("ViewModel");
+
if (propertyInfo == null)
return null;
return (IMvxViewModel)propertyInfo.GetGetMethod().Invoke(view, new object[] {});
+#endif
}
}
}
@@ -166,26 +166,14 @@ protected virtual void InitializeViews()
where !type.IsAbstract
&& expectedInterfaceType.GetTypeInfo().IsAssignableFrom(type)
&& !type.Name.StartsWith("Base")
- let viewModelPropertyInfo = HackGetDeclaredProperty(type, "ViewModel")
+ let viewModelPropertyInfo = type.RecursiveGetDeclaredProperty("ViewModel")
where viewModelPropertyInfo != null
let viewModelType = viewModelPropertyInfo.PropertyType
select new {type, viewModelType};
return views.ToDictionary(x => x.viewModelType, x => x.type.AsType());
}
- private static PropertyInfo HackGetDeclaredProperty(TypeInfo type, string name)
- {
- var candidate = type.GetDeclaredProperty(name);
- if (candidate != null)
- return candidate;
-
- var baseType = type.BaseType;
- if (baseType != null)
- return HackGetDeclaredProperty(baseType.GetTypeInfo(), name);
-
- return null;
- }
#else
protected IDictionary<Type, Type> GetViewModelViewLookup(Assembly assembly, Type expectedInterfaceType)
{
@@ -0,0 +1,22 @@
+#region Copyright
+// <copyright file="IMvxWinRTViewPresenter.cs" company="Cirrious">
+// (c) Copyright Cirrious. http://www.cirrious.com
+// This source is subject to the Microsoft Public License (Ms-PL)
+// Please see license.txt on http://opensource.org/licenses/ms-pl.html
+// All other rights reserved.
+// </copyright>
+//
+// Project Lead - Stuart Lodge, Cirrious. http://www.cirrious.com
+#endregion
+
+using Cirrious.MvvmCross.Interfaces.ViewModels;
+using Cirrious.MvvmCross.Views;
+
+namespace Cirrious.MvvmCross.WinRT.Interfaces
+{
+ public interface IMvxWinRTViewPresenter
+ {
+ void Show(MvxShowViewModelRequest request);
+ void Close(IMvxViewModel viewModel);
+ }
+}
@@ -34,13 +34,23 @@ protected MvxBaseWinRTSetup(Frame rootFrame)
protected override MvxViewsContainer CreateViewsContainer()
{
- var container = CreateViewsContainer(_rootFrame);;
- return container;
+ return new MvxWinRTViewsContainer();
}
- protected virtual MvxWinRTViewsContainer CreateViewsContainer(Frame rootFrame)
+ protected override MvvmCross.Interfaces.Views.IMvxViewDispatcherProvider CreateViewDispatcherProvider()
{
- return new MvxWinRTViewsContainer(rootFrame);
+ return CreateViewDispatcherProvider(_rootFrame);
+ }
+
+ protected virtual IMvxWinRTViewPresenter CreateViewPresenter(Frame rootFrame)
+ {
+ return new MvxWinRTViewPresenter(rootFrame);
+ }
+
+ protected virtual MvxWinRTViewDispatcherProvider CreateViewDispatcherProvider(Frame rootFrame)
+ {
+ var presenter = CreateViewPresenter(_rootFrame);
+ return new MvxWinRTViewDispatcherProvider(presenter, rootFrame);
}
protected override IDictionary<Type, Type> GetViewModelViewLookup()
@@ -11,11 +11,10 @@
#region using
using System;
-using Cirrious.MvvmCross.ExtensionMethods;
-using Cirrious.MvvmCross.Interfaces.ServiceProvider;
+using Cirrious.MvvmCross.Interfaces.ViewModels;
using Cirrious.MvvmCross.Interfaces.Views;
-using Cirrious.MvvmCross.Platform.Diagnostics;
using Cirrious.MvvmCross.Views;
+using Cirrious.MvvmCross.WinRT.Interfaces;
using Cirrious.MvvmCross.WinRT.Platform;
using Windows.UI.Xaml.Controls;
@@ -26,38 +25,27 @@ namespace Cirrious.MvvmCross.WinRT.Views
public class MvxWinRTViewDispatcher
: MvxMainThreadDispatcher
, IMvxViewDispatcher
- , IMvxServiceConsumer<IMvxViewsContainer>
{
+ private readonly IMvxWinRTViewPresenter _presenter;
private readonly Frame _rootFrame;
- public MvxWinRTViewDispatcher(Frame rootFrame)
+ public MvxWinRTViewDispatcher(IMvxWinRTViewPresenter presenter, Frame rootFrame)
: base(rootFrame.Dispatcher)
{
+ _presenter = presenter;
_rootFrame = rootFrame;
}
#region IMvxViewDispatcher Members
public bool RequestNavigate(MvxShowViewModelRequest request)
{
- var requestTranslator = this.GetService<IMvxViewsContainer>();
- var viewType = requestTranslator.GetViewType(request.ViewModelType);
- return RequestMainThreadAction(() =>
- {
- try
- {
- _rootFrame.Navigate(viewType, request);
- }
- catch (Exception exception)
- {
- MvxTrace.Trace("Error seen during navigation request to {0} - error {1}", request.ViewModelType.Name, exception.ToLongString());
- }
- });
+ return RequestMainThreadAction(() => _presenter.Show(request));
}
- public bool RequestNavigateBack()
+ public bool RequestClose(IMvxViewModel viewModel)
{
- return RequestMainThreadAction(() => _rootFrame.GoBack());
+ return RequestMainThreadAction(() => _presenter.Close(viewModel));
}
public bool RequestRemoveBackStep()
@@ -0,0 +1,34 @@
+#region Copyright
+// <copyright file="MvxWinRTViewDispatcherProvider.cs" company="Cirrious">
+// (c) Copyright Cirrious. http://www.cirrious.com
+// This source is subject to the Microsoft Public License (Ms-PL)
+// Please see license.txt on http://opensource.org/licenses/ms-pl.html
+// All other rights reserved.
+// </copyright>
+//
+// Project Lead - Stuart Lodge, Cirrious. http://www.cirrious.com
+#endregion
+using Cirrious.MvvmCross.Interfaces.Views;
+using Cirrious.MvvmCross.WinRT.Interfaces;
+using Windows.UI.Xaml.Controls;
+
+namespace Cirrious.MvvmCross.WinRT.Views
+{
+ public class MvxWinRTViewDispatcherProvider
+ : IMvxViewDispatcherProvider
+ {
+ private readonly IMvxWinRTViewPresenter _presenter;
+ private readonly Frame _rootFrame;
+
+ public MvxWinRTViewDispatcherProvider(IMvxWinRTViewPresenter presenter, Frame frame)
+ {
+ _presenter = presenter;
+ _rootFrame = frame;
+ }
+
+ public IMvxViewDispatcher Dispatcher
+ {
+ get { return new MvxWinRTViewDispatcher(_presenter, _rootFrame); }
+ }
+ }
+}
@@ -0,0 +1,54 @@
+#region Copyright
+// <copyright file="MvxWinRTViewPresenter.cs" company="Cirrious">
+// (c) Copyright Cirrious. http://www.cirrious.com
+// This source is subject to the Microsoft Public License (Ms-PL)
+// Please see license.txt on http://opensource.org/licenses/ms-pl.html
+// All other rights reserved.
+// </copyright>
+//
+// Project Lead - Stuart Lodge, Cirrious. http://www.cirrious.com
+#endregion
+using System;
+using Cirrious.MvvmCross.ExtensionMethods;
+using Cirrious.MvvmCross.Interfaces.ServiceProvider;
+using Cirrious.MvvmCross.Interfaces.ViewModels;
+using Cirrious.MvvmCross.Interfaces.Views;
+using Cirrious.MvvmCross.Platform.Diagnostics;
+using Cirrious.MvvmCross.Views;
+using Cirrious.MvvmCross.WinRT.Interfaces;
+using Windows.UI.Xaml.Controls;
+
+namespace Cirrious.MvvmCross.WinRT.Views
+{
+ public class MvxWinRTViewPresenter
+ : IMvxWinRTViewPresenter
+ , IMvxServiceConsumer<IMvxViewsContainer>
+ {
+ private readonly Frame _rootFrame;
+
+ public MvxWinRTViewPresenter(Frame rootFrame)
+ {
+ _rootFrame = rootFrame;
+ }
+
+ public void Show(MvxShowViewModelRequest request)
+ {
+ try
+ {
+ var requestTranslator = this.GetService<IMvxViewsContainer>();
+ var viewType = requestTranslator.GetViewType(request.ViewModelType);
+ _rootFrame.Navigate(viewType, request);
+ }
+ catch (Exception exception)
+ {
+ MvxTrace.Trace("Error seen during navigation request to {0} - error {1}", request.ViewModelType.Name, exception.ToLongString());
+ }
+ }
+
+ public void Close(IMvxViewModel viewModel)
+ {
+#warning Should do more here - e.g. should check _rootFrame's current is a view for viewmodel
+ _rootFrame.GoBack();
+ }
+ }
+}
@@ -18,19 +18,9 @@
namespace Cirrious.MvvmCross.WinRT.Views
{
- public class MvxWinRTViewsContainer
+ public class MvxWinRTViewsContainer
: MvxViewsContainer
{
- private readonly Frame _rootFrame;
-
- public MvxWinRTViewsContainer(Frame frame)
- {
- _rootFrame = frame;
- }
-
- public override IMvxViewDispatcher Dispatcher
- {
- get { return new MvxWinRTViewDispatcher(_rootFrame); }
- }
+ // nothing to do here!
}
}
@@ -120,7 +120,7 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Cirrious.MvvmCross.WinRT">
- <HintPath>..\..\MvvmCross\Cirrious\Cirrious.MvvmCross\bin\x86\Debug\Cirrious.MvvmCross.WinRT.dll</HintPath>
+ <HintPath>..\Libs\WinRT\x86\Debug\Cirrious.MvvmCross.WinRT.dll</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' ">
@@ -174,16 +174,16 @@
</Page>
</ItemGroup>
<ItemGroup>
- <Reference Include="Cirrious.MvvmCross.WinRT">
- <HintPath>..\..\MvvmCross\Cirrious\Cirrious.MvvmCross\bin\x86\Debug\Cirrious.MvvmCross.WinRT.dll</HintPath>
- </Reference>
- </ItemGroup>
- <ItemGroup>
<ProjectReference Include="..\TwitterSearch.Core\TwitterSearch.Core.Win8.csproj">
<Project>{065df474-140d-4393-aa19-4b041daba563}</Project>
<Name>TwitterSearch.Core.Win8</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Reference Include="Cirrious.MvvmCross.WinRT">
+ <HintPath>..\Libs\WinRT\x86\Debug\Cirrious.MvvmCross.WinRT.dll</HintPath>
+ </Reference>
+ </ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' ">
<VisualStudioVersion>11.0</VisualStudioVersion>
</PropertyGroup>

0 comments on commit 52b71f2

Please sign in to comment.