Permalink
Browse files

The final version for Caliburn.Micro DataTemplateSelector blog post

  • Loading branch information...
1 parent a4f324d commit 1e6353df99899b602f240f21217f078b078b9df4 @mikoskinen committed Jan 20, 2012
Showing with 167 additions and 14,469 deletions.
  1. +6 −4 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/Bootstrapper.cs
  2. +0 −108 ...-datatemplate-selector/caliburn-micro-datatemplate-selector/Caliburn.Micro/ContainerExtensions.cs
  3. +0 −87 ...cro-datatemplate-selector/caliburn-micro-datatemplate-selector/Caliburn.Micro/ExtensionMethods.cs
  4. +0 −206 ...icro-datatemplate-selector/caliburn-micro-datatemplate-selector/Caliburn.Micro/SimpleContainer.cs
  5. +16 −0 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/File.cs
  6. +20 −0 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/FileView.xaml
  7. +22 −0 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/FileView.xaml.cs
  8. +18 −0 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/Folder.cs
  9. +21 −0 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/FolderView.xaml
  10. +22 −0 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/FolderView.xaml.cs
  11. BIN ...urn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/Icons/appbar.folder.rest.png
  12. BIN caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/Icons/appbar.save.rest.png
  13. +6 −7 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/MainPage.xaml
  14. +12 −4 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/MainPageViewModel.cs
  15. +24 −10 ...emplate-selector/caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector.csproj
  16. +0 −5 caliburn-micro-datatemplate-selector/caliburn-micro-datatemplate-selector/packages.config
  17. BIN caliburn-micro-datatemplate-selector/lib/Caliburn.Micro.Extensions.dll
  18. BIN caliburn-micro-datatemplate-selector/lib/Caliburn.Micro.dll
  19. BIN ...template-selector/{packages/Caliburn.Micro.1.2.0/lib/SL40 → lib}/System.Windows.Interactivity.dll
  20. BIN caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/Caliburn.Micro.1.2.0.nupkg
  21. BIN caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/Net40/Caliburn.Micro.dll
  22. BIN caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/Net40/Caliburn.Micro.pdb
  23. +0 −2,422 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/Net40/Caliburn.Micro.xml
  24. BIN ...ro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/Net40/System.Windows.Interactivity.dll
  25. +0 −1,072 ...ro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/Net40/System.Windows.Interactivity.xml
  26. BIN ...cro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40-wp/Caliburn.Micro.Extensions.dll
  27. BIN ...cro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40-wp/Caliburn.Micro.Extensions.pdb
  28. +0 −900 ...cro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40-wp/Caliburn.Micro.Extensions.xml
  29. BIN caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40-wp/Caliburn.Micro.dll
  30. BIN caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40-wp/Caliburn.Micro.pdb
  31. +0 −2,830 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40-wp/Caliburn.Micro.xml
  32. BIN ...-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40-wp/System.Windows.Interactivity.dll
  33. +0 −964 ...-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40-wp/System.Windows.Interactivity.xml
  34. BIN caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/Caliburn.Micro.dll
  35. BIN caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/Caliburn.Micro.pdb
  36. +0 −2,439 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/Caliburn.Micro.xml
  37. BIN ...rn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/System.Windows.Controls.dll
  38. +0 −1,726 ...rn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/System.Windows.Controls.xml
  39. +0 −1,025 ...cro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/System.Windows.Interactivity.xml
  40. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/ar/System.Windows.Controls.resources.dll
  41. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/bg/System.Windows.Controls.resources.dll
  42. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/ca/System.Windows.Controls.resources.dll
  43. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/cs/System.Windows.Controls.resources.dll
  44. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/da/System.Windows.Controls.resources.dll
  45. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/de/System.Windows.Controls.resources.dll
  46. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/el/System.Windows.Controls.resources.dll
  47. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/es/System.Windows.Controls.resources.dll
  48. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/et/System.Windows.Controls.resources.dll
  49. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/eu/System.Windows.Controls.resources.dll
  50. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/fi/System.Windows.Controls.resources.dll
  51. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/fr/System.Windows.Controls.resources.dll
  52. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/he/System.Windows.Controls.resources.dll
  53. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/hr/System.Windows.Controls.resources.dll
  54. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/hu/System.Windows.Controls.resources.dll
  55. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/id/System.Windows.Controls.resources.dll
  56. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/it/System.Windows.Controls.resources.dll
  57. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/ja/System.Windows.Controls.resources.dll
  58. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/ko/System.Windows.Controls.resources.dll
  59. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/lt/System.Windows.Controls.resources.dll
  60. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/lv/System.Windows.Controls.resources.dll
  61. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/ms/System.Windows.Controls.resources.dll
  62. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/nl/System.Windows.Controls.resources.dll
  63. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/no/System.Windows.Controls.resources.dll
  64. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/pl/System.Windows.Controls.resources.dll
  65. BIN ...plate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/pt-BR/System.Windows.Controls.resources.dll
  66. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/pt/System.Windows.Controls.resources.dll
  67. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/ro/System.Windows.Controls.resources.dll
  68. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/ru/System.Windows.Controls.resources.dll
  69. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/sk/System.Windows.Controls.resources.dll
  70. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/sl/System.Windows.Controls.resources.dll
  71. BIN ...-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/sr-Cyrl-CS/System.Windows.Controls.resources.dll
  72. BIN ...-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/sr-Latn-CS/System.Windows.Controls.resources.dll
  73. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/sv/System.Windows.Controls.resources.dll
  74. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/th/System.Windows.Controls.resources.dll
  75. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/tr/System.Windows.Controls.resources.dll
  76. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/uk/System.Windows.Controls.resources.dll
  77. BIN ...template-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/vi/System.Windows.Controls.resources.dll
  78. BIN ...ate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/zh-Hans/System.Windows.Controls.resources.dll
  79. BIN ...ate-selector/packages/Caliburn.Micro.1.2.0/lib/SL40/zh-Hant/System.Windows.Controls.resources.dll
  80. +0 −56 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/NET40/AppBootstrapper.cs
  81. +0 −3 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/NET40/IShell.cs
  82. +0 −12 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/NET40/ShellView.xaml
  83. +0 −6 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/NET40/ShellViewModel.cs
  84. +0 −72 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/SL40-WP/AppBootstrapper.cs
  85. +0 −3 ...burn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/SL40-WP/MainPageViewModel.cs
  86. +0 −56 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/SL40/AppBootstrapper.cs
  87. +0 −3 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/SL40/IShell.cs
  88. +0 −12 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/SL40/ShellView.xaml
  89. +0 −6 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/SL40/ShellViewModel.cs
  90. +0 −26 caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.1.2.0/tools/install.ps1
  91. BIN ...atatemplate-selector/packages/Caliburn.Micro.Container.1.2.0/Caliburn.Micro.Container.1.2.0.nupkg
  92. +0 −108 ...te-selector/packages/Caliburn.Micro.Container.1.2.0/content/Caliburn.Micro/ContainerExtensions.cs
  93. +0 −87 ...plate-selector/packages/Caliburn.Micro.Container.1.2.0/content/Caliburn.Micro/ExtensionMethods.cs
  94. +0 −206 ...mplate-selector/packages/Caliburn.Micro.Container.1.2.0/content/Caliburn.Micro/SimpleContainer.cs
  95. BIN caliburn-micro-datatemplate-selector/packages/Caliburn.Micro.Container.1.2.0/nuget.exe
  96. +0 −4 caliburn-micro-datatemplate-selector/packages/repositories.config
@@ -2,16 +2,18 @@
namespace caliburn_micro_datatemplate_selector
{
- public class MyBootstrapper : Bootstrapper
+ public class MyBootstrapper : PhoneBootstrapper
{
- private SimpleContainer container;
+ private PhoneContainer container;
protected override void Configure()
{
- container = new SimpleContainer();
+ container = new PhoneContainer(RootFrame);
+ container.RegisterPhoneServices();
container.PerRequest<MainPageViewModel>();
- Caliburn.Micro.ViewLocator.NameTransformer.AddRule("");
+ ViewLocator.NameTransformer.AddRule(typeof(File).FullName, typeof(FileView).FullName);
+ ViewLocator.NameTransformer.AddRule(typeof (Folder).FullName, typeof (FolderView).FullName);
}
protected override object GetInstance(System.Type service, string key)
@@ -1,108 +0,0 @@
-namespace Caliburn.Micro {
- using System;
- using System.Linq;
- using System.Reflection;
-
- /// <summary>
- /// Extension methods for the <see cref="SimpleContainer"/>.
- /// </summary>
- public static class ContainerExtensions {
- /// <summary>
- /// Registers a singleton.
- /// </summary>
- /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
- /// <param name="container">The container.</param>
- /// <returns>The container.</returns>
- public static SimpleContainer Singleton<TImplementation>(this SimpleContainer container) {
- container.RegisterSingleton(typeof(TImplementation), null, typeof(TImplementation));
- return container;
- }
-
- /// <summary>
- /// Registers a singleton.
- /// </summary>
- /// <typeparam name="TService">The type of the service.</typeparam>
- /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
- /// <param name="container">The container.</param>
- /// <returns>The container.</returns>
- public static SimpleContainer Singleton<TService, TImplementation>(this SimpleContainer container)
- where TImplementation : TService {
- container.RegisterSingleton(typeof(TService), null, typeof(TImplementation));
- return container;
- }
-
- /// <summary>
- /// Registers an service to be created on each request.
- /// </summary>
- /// <typeparam name="TService">The type of the service.</typeparam>
- /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
- /// <param name="container">The container.</param>
- /// <returns>The container.</returns>
- public static SimpleContainer PerRequest<TService, TImplementation>(this SimpleContainer container)
- where TImplementation : TService {
- container.RegisterPerRequest(typeof(TService), null, typeof(TImplementation));
- return container;
- }
-
- /// <summary>
- /// Registers an service to be created on each request.
- /// </summary>
- /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
- /// <param name="container">The container.</param>
- /// <returns>The container.</returns>
- public static SimpleContainer PerRequest<TImplementation>(this SimpleContainer container) {
- container.RegisterPerRequest(typeof(TImplementation), null, typeof(TImplementation));
- return container;
- }
-
- /// <summary>
- /// Registers an instance with the container.
- /// </summary>
- /// <typeparam name="TService">The type of the service.</typeparam>
- /// <param name="container">The container.</param>
- /// <param name="instance">The instance.</param>
- /// <returns>The container.</returns>
- public static SimpleContainer Instance<TService>(this SimpleContainer container, TService instance) {
- container.RegisterInstance(typeof(TService), null, instance);
- return container;
- }
-
- /// <summary>
- /// Registers a custom service handler with the container.
- /// </summary>
- /// <typeparam name="TService">The type of the service.</typeparam>
- /// <param name="container">The container.</param>
- /// <param name="handler">The handler.</param>
- /// <returns>The container.</returns>
- public static SimpleContainer Handler<TService>(this SimpleContainer container, Func<SimpleContainer, object> handler) {
- container.RegisterHandler(typeof(TService), null, handler);
- return container;
- }
-
- /// <summary>
- /// Registers all specified types in an assembly as singletong in the container.
- /// </summary>
- /// <typeparam name="TService">The type of the service.</typeparam>
- /// <param name="container">The container.</param>
- /// <param name="assembly">The assembly.</param>
- /// <param name="filter">The type filter.</param>
- /// <returns>The container.</returns>
- public static SimpleContainer AllTypesOf<TService>(this SimpleContainer container, Assembly assembly, Func<Type, bool> filter = null) {
- if(filter == null)
- filter = type => true;
-
- var types = from type in assembly.GetTypes()
- where typeof(TService).IsAssignableFrom(type)
- && !type.IsAbstract
- && !type.IsInterface
- && filter(type)
- select type;
-
- foreach(var type in types) {
- container.RegisterSingleton(typeof(TService), null, type);
- }
-
- return container;
- }
- }
-}
@@ -1,87 +0,0 @@
-namespace Caliburn.Micro
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Reflection;
-
- /// <summary>
- /// Generic extension methods used by the framework.
- /// </summary>
- public static class ExtensionMethods
- {
- /// <summary>
- /// Gets all the attributes of a particular type.
- /// </summary>
- /// <typeparam name="T">The type of attributes to get.</typeparam>
- /// <param name="member">The member to inspect for attributes.</param>
- /// <param name="inherit">Whether or not to search for inherited attributes.</param>
- /// <returns>The list of attributes found.</returns>
- public static IEnumerable<T> GetAttributes<T>(this MemberInfo member, bool inherit) {
- return Attribute.GetCustomAttributes(member, inherit).OfType<T>();
- }
-
- /// <summary>
- /// Applies the action to each element in the list.
- /// </summary>
- /// <typeparam name="T">The enumerable item's type.</typeparam>
- /// <param name="enumerable">The elements to enumerate.</param>
- /// <param name="action">The action to apply to each item in the list.</param>
- public static void Apply<T>(this IEnumerable<T> enumerable, Action<T> action) {
- foreach(var item in enumerable)
- action(item);
- }
-
- /// <summary>
- /// Converts an expression into a <see cref="MemberInfo"/>.
- /// </summary>
- /// <param name="expression">The expression to convert.</param>
- /// <returns>The member info.</returns>
- public static MemberInfo GetMemberInfo(this Expression expression) {
- var lambda = (LambdaExpression)expression;
-
- MemberExpression memberExpression;
- if(lambda.Body is UnaryExpression) {
- var unaryExpression = (UnaryExpression)lambda.Body;
- memberExpression = (MemberExpression)unaryExpression.Operand;
- }
- else
- memberExpression = (MemberExpression)lambda.Body;
-
- return memberExpression.Member;
- }
-
-#if WP7
- //Method missing in WP7 Linq
-
- /// <summary>
- /// Merges two sequences by using the specified predicate function.
- /// </summary>
- /// <typeparam name="TFirst">The type of the elements of the first input sequence.</typeparam>
- /// <typeparam name="TSecond">The type of the elements of the second input sequence.</typeparam>
- /// <typeparam name="TResult">The type of the elements of the result sequence.</typeparam>
- /// <param name="first">The first sequence to merge.</param>
- /// <param name="second">The second sequence to merge.</param>
- /// <param name="resultSelector"> A function that specifies how to merge the elements from the two sequences.</param>
- /// <returns>An System.Collections.Generic.IEnumerable&lt;T&gt; that contains merged elements of two input sequences.</returns>
- public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
- {
- if (first == null)
- throw new ArgumentNullException("first");
- if (second == null)
- throw new ArgumentNullException("second");
- if (resultSelector == null)
- throw new ArgumentNullException("resultSelector");
-
- var enumFirst = first.GetEnumerator();
- var enumSecond = second.GetEnumerator();
-
- while (enumFirst.MoveNext() && enumSecond.MoveNext()) {
- yield return resultSelector(enumFirst.Current, enumSecond.Current);
- }
- }
-
-#endif
- }
-}
Oops, something went wrong.

0 comments on commit 1e6353d

Please sign in to comment.