예제 #1
0
        }                                        // proc RefreshDefaultResourcesAsync

        private async Task RefreshTemplatesAsync()
        {
            var priority = 1;

            using (var xml = PpsXmlPosition.CreateLinePositionReader(await OpenXmlDocumentAsync("wpf/templates.xaml", true, true)))
            {
                if (xml == null)
                {
                    return;                     // no templates found
                }
                // read root
                await xml.ReadStartElementAsync(StuffUI.xnTemplates);

                while (xml.NodeType != XmlNodeType.EndElement)
                {
                    if (xml.NodeType == XmlNodeType.Element)
                    {
                        if (xml.IsName(StuffUI.xnResources))
                        {
                            if (!await xml.ReadAsync())
                            {
                                break;                                 // fetch element
                            }
                            // check for a global resource dictionary, and update the main resources
                            await UpdateResourcesAsync(xml);

                            await xml.ReadEndElementAsync();                             // resource
                        }
                        else if (xml.IsName(StuffUI.xnTemplate))
                        {
                            var key = xml.GetAttribute("key", String.Empty);
                            if (String.IsNullOrEmpty(key))
                            {
                                xml.Skip();
                                break;
                            }

                            var templateDefinition = templateDefinitions[key];
                            if (templateDefinition == null)
                            {
                                templateDefinition = new PpsDataTemplateDefinition(this, key);
                                templateDefinitions.AppendItem(templateDefinition);
                            }
                            priority = await templateDefinition.AppendTemplateAsync(xml, priority);

                            await xml.ReadEndElementAsync();

                            await xml.SkipAsync();
                        }
                        else
                        {
                            await xml.SkipAsync();
                        }
                    }
                    else
                    {
                        await xml.ReadAsync();
                    }
                }

                await xml.ReadEndElementAsync(); // templates
            }                                    // using xml

            // remove unused templates
            // todo:
        }         // proc RefreshTemplatesAsync
예제 #2
0
 public DefaultDataTemplateSelector(PpsDataTemplateDefinition templateDefinition)
 {
     this.templateDefinition = templateDefinition ?? throw new ArgumentNullException(nameof(templateDefinition));
 }