public DataTemplate CreateWithViewModelMappings(ViewViewModelMap map) { var context = CreateContext(map); var dataTemplateXaml = CreateDataTemplateXaml(map.ViewModelType.Name, map.ViewType.Name); var result = (DataTemplate)XamlReader.Parse(dataTemplateXaml, context); return(result); }
private void AddDataTemplate(IDictionary resourceDictionary, ViewViewModelMap map) { var dataTemplate = _dataTemplateFactory.CreateWithViewModelMappings(map); if (dataTemplate.DataTemplateKey == null) { return; } resourceDictionary.Add(dataTemplate.DataTemplateKey, dataTemplate); }
private static ParserContext CreateContext(ViewViewModelMap map) { var context = new ParserContext { XamlTypeMapper = new XamlTypeMapper(Array.Empty <string>()) }; context.XamlTypeMapper.AddMappingProcessingInstruction( "vm", map.ViewModelType.Namespace ?? string.Empty, map.ViewModelType.Assembly.FullName ?? string.Empty); context.XamlTypeMapper.AddMappingProcessingInstruction( "v", map.ViewType.Namespace ?? string.Empty, map.ViewType.Assembly.FullName ?? string.Empty); context.XmlnsDictionary.Add(string.Empty, "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml"); context.XmlnsDictionary.Add("vm", "vm"); context.XmlnsDictionary.Add("v", "v"); return(context); }
private void ApplyDataTemplate(IDictionary resourceDictionary, ViewViewModelMap map) { var dataTemplate = _dataTemplateFactory.CreateWithMapping(map); resourceDictionary.Add(dataTemplate.DataTemplateKey, dataTemplate); }