This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GalaSoft.MvvmLight; | |
using GalaSoft.MvvmLight.Command; | |
internal class TestViewModel : ViewModel | |
{ | |
private RelayCommand myGreatCommand; | |
// ... some stuff here | |
public override void Cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Grid> | |
<Button Command="{Binding MyGreatCommand}" Content="Test"></Button> | |
</Grid> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public RelayCommand MyGreatCommand | |
{ | |
get | |
{ | |
return this.myGreatCommand ?? ( | |
this.myGreatCommand = new RelayCommand( | |
() => | |
{ | |
// some code here | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void AddDataTemplate(Type viewType, Type viewModelType) | |
{ | |
DataTemplate dataTemplate = this.CreateTemplate(viewType, viewModelType); | |
if (!Application.Current.Resources.Contains(dataTemplate.DataTemplateKey)) | |
{ | |
Application.Current.Resources.Add(dataTemplate.DataTemplateKey, dataTemplate); | |
} | |
else | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ResourceDictionary | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:v="clr-namespace:PP.Blog.Views" | |
xmlns:vm="clr-namespace:PP.Blog.ViewModels"> | |
<DataTemplate DataType="{x:Type vm:HomeViewModel}"> | |
<v:HomeView /> | |
</DataTemplate> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private DataTemplate CreateTemplate(Type viewType, Type viewModelType) | |
{ | |
const string xamlTemplate = | |
"<DataTemplate DataType=\"{{x:Type xViewModels:{0}}}\"><xViews:{1}></xViews:{1}></DataTemplate>"; | |
var xaml = String.Format(xamlTemplate, viewModelType.Name, viewType.Name); | |
var context = new ParserContext(); | |
context.XamlTypeMapper = new XamlTypeMapper(new string[0]); | |
context.XamlTypeMapper.AddMappingProcessingInstruction("xViewModels", viewModelType.Namespace, viewModelType.Assembly.FullName); | |
context.XamlTypeMapper.AddMappingProcessingInstruction("xViews", viewType.Namespace, viewType.Assembly.FullName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureViewModels(IUnityContainer container) | |
{ | |
Assembly currentAssembly = Assembly.GetCallingAssembly(); | |
IEnumerable<Type> allAssemblyTypes = currentAssembly.GetTypes(); | |
foreach (var type in allAssemblyTypes) | |
{ | |
if (this.ViewModelNamesOnly(type) != null) | |
{ | |
Type viewType = this.GetMatchingViewType(type); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Practices.Unity; | |
using System; | |
using System.Collections.Generic; | |
using System.Reflection; | |
using System.Windows; | |
using System.Windows.Markup; | |
namespace PP.Blog.WpfViewModelsResolver | |
{ | |
class ViewModelsResolver |