public void UpdatePartsFromMetadata() { if (!this.IsEnabled) { this.parts.Clear(); this.PartsList.Clear(); this.lastEditingContainer = (SceneNode)null; } else { List <TemplatePartAttributeRecord> list = new List <TemplatePartAttributeRecord>((IEnumerable <TemplatePartAttributeRecord>)ProjectAttributeHelper.GetTemplatePartAttributes(this.TargetTemplate.ProjectContext.ResolveType(this.TargetTemplate.ControlTemplateTargetTypeId), (ITypeResolver)ProjectContext.GetProjectContext(this.viewModel.ProjectContext))); list.Sort((Comparison <TemplatePartAttributeRecord>)((first, second) => string.Compare(first.NameAttribute, second.NameAttribute, StringComparison.CurrentCulture))); this.parts.Clear(); this.PartsList.Clear(); foreach (TemplatePartAttributeRecord partAttributeRecord in list) { if (!string.IsNullOrEmpty(partAttributeRecord.NameAttribute) && !(partAttributeRecord.TypeAttribute == (Type)null)) { ITypeId type = (ITypeId)this.TargetTemplate.ProjectContext.GetType(partAttributeRecord.TypeAttribute); if (PlatformTypes.FrameworkElement.IsAssignableFrom(type)) { PartInPartsExplorer partInPartsExplorer = new PartInPartsExplorer(partAttributeRecord.NameAttribute, type); if (!this.parts.ContainsKey(partAttributeRecord.NameAttribute)) { PartsModel.PartsGroup partsGroup = new PartsModel.PartsGroup(); partsGroup.Add(partInPartsExplorer); this.parts.Add(partAttributeRecord.NameAttribute, partsGroup); } else { this.parts[partAttributeRecord.NameAttribute].Add(partInPartsExplorer); } this.PartsList.Add(partInPartsExplorer); } } } this.lastEditingContainer = this.viewModel.ActiveEditingContainer; } }
private void Rebuild() { if (this.EditingProperty == null) { return; } this.EditingProperty.Recache(); this.states.Clear(); if (this.EditingProperty.ObjectSet.IsHomogenous && this.EditingProperty.ObjectSet.Count > 0) { BehaviorTargetedTriggerActionNode triggerActionNode = this.EditingProperty.SceneNodeObjectSet.Objects[0] as BehaviorTargetedTriggerActionNode; if (triggerActionNode == null || triggerActionNode.TargetObject == null && string.IsNullOrEmpty(triggerActionNode.TargetName)) { SceneNode editingContainer = this.viewModel.ActiveEditingContainer; SceneNode hostNode = VisualStateManagerSceneNode.GetHostNode(this.viewModel.ActiveEditingContainer); if (hostNode != null) { foreach (VisualStateGroupSceneNode stateGroupSceneNode in (IEnumerable <VisualStateGroupSceneNode>)VisualStateManagerSceneNode.GetStateGroups(hostNode)) { foreach (SceneNode sceneNode in (IEnumerable <VisualStateSceneNode>)stateGroupSceneNode.States) { this.states.Add(new StateInfo(sceneNode.Name, stateGroupSceneNode.Name)); } } } ControlTemplateElement controlTemplateElement = this.viewModel.ActiveEditingContainer as ControlTemplateElement; if (controlTemplateElement != null) { IType type = this.viewModel.ProjectContext.ResolveType(controlTemplateElement.ControlTemplateTargetTypeId); foreach (DefaultStateRecord defaultStateRecord in ProjectAttributeHelper.GetDefaultStateRecords(type, (ITypeResolver)(this.viewModel.ProjectContext as ProjectContext))) { this.AddStateInfoIfNeeded(defaultStateRecord.StateName, defaultStateRecord.GroupName, type); } } } else if (triggerActionNode.TargetNode != null && triggerActionNode.TargetNode.IsViewObjectValid) { IViewControl viewControl = triggerActionNode.TargetNode.ViewObject as IViewControl; if (viewControl != null) { object stateManagerHost = viewControl.VisualStateManagerHost; if (stateManagerHost != null) { foreach (object group in (IEnumerable)StatePickerEditor.GetVisualStateGroups(stateManagerHost, (ITypeResolver)triggerActionNode.ProjectContext)) { string stateGroupName = this.GetStateGroupName(group); foreach (object state in (IEnumerable)this.GetStates(group)) { this.states.Add(new StateInfo(this.GetStateName(state), stateGroupName)); } } } IType type = triggerActionNode.TargetNode.ProjectContext.GetType(triggerActionNode.TargetNode.TargetType); foreach (DefaultStateRecord defaultStateRecord in ProjectAttributeHelper.GetDefaultStateRecords(triggerActionNode.TargetNode.Type, (ITypeResolver)(this.viewModel.ProjectContext as ProjectContext))) { this.AddStateInfoIfNeeded(defaultStateRecord.StateName, defaultStateRecord.GroupName, type); } } } } this.states.RemoveAll((Predicate <StateInfo>)(stateInfo => { if (!string.IsNullOrEmpty(stateInfo.GroupName) && !string.IsNullOrEmpty(stateInfo.StateName) && !stateInfo.GroupName.StartsWith(VisualStateManagerSceneNode.SketchFlowAnimationXamlDelimiter, StringComparison.Ordinal)) { return(stateInfo.StateName.StartsWith("_BlendEditTimeState-", StringComparison.Ordinal)); } return(true); })); this.statesView = CollectionViewSource.GetDefaultView(this.states); PropertyGroupDescription groupDescription = new PropertyGroupDescription(); groupDescription.PropertyName = "GroupName"; this.statesView.GroupDescriptions.Clear(); this.statesView.GroupDescriptions.Add((GroupDescription)groupDescription); this.OnPropertyChanged("CurrentState"); this.OnPropertyChanged("States"); }
private void ResolveDefaultStyle(SceneElement targetElement, object defaultStyleKey, bool allowDefaultStyle, out DocumentNode currentStyle, out bool isThemeStyle, out IList <DocumentCompositeNode> auxillaryResources) { IProjectContext projectContext1 = this.SceneViewModel.ProjectContext; ThemeContentProvider themeContentProvider = this.DesignerContext.ThemeContentProvider; currentStyle = (DocumentNode)null; isThemeStyle = false; auxillaryResources = (IList <DocumentCompositeNode>)null; if (defaultStyleKey == null) { return; } IAssembly runtimeAssembly = targetElement.Type.RuntimeAssembly; IAssembly targetAssembly = PlatformTypeHelper.GetTargetAssembly(targetElement.Type); Type type1 = defaultStyleKey as Type; if (type1 != (Type)null) { ITypeId typeId = (ITypeId)projectContext1.GetType(type1); if (typeId != null) { IType type2 = projectContext1.ResolveType(typeId); runtimeAssembly = type2.RuntimeAssembly; targetAssembly = PlatformTypeHelper.GetTargetAssembly(type2); } } IAssembly designAssembly = projectContext1.GetDesignAssembly(runtimeAssembly); if (designAssembly != null) { currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, designAssembly, designAssembly, defaultStyleKey, out auxillaryResources); if (currentStyle != null) { return; } } if (!PlatformTypes.IsPlatformType((ITypeId)this.Type)) { foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects) { IProjectContext projectContext2 = (IProjectContext)ProjectXamlContext.GetProjectContext(project); if (projectContext2 != null && runtimeAssembly.Equals((object)projectContext2.ProjectAssembly)) { currentStyle = themeContentProvider.GetThemeResourceFromProject(project, defaultStyleKey, out auxillaryResources); if (currentStyle != null) { return; } } } } else if (!allowDefaultStyle || projectContext1.PlatformMetadata.TargetFramework.Identifier == ".NETFramework" && projectContext1.PlatformMetadata.TargetFramework.Version < projectContext1.PlatformMetadata.RuntimeFramework.Version) { currentStyle = themeContentProvider.GetThemeResourceFromPlatform(projectContext1.Platform, defaultStyleKey, out auxillaryResources); if (currentStyle != null) { isThemeStyle = true; return; } } if (!projectContext1.IsCapabilitySet(PlatformCapability.IsWpf)) { currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, runtimeAssembly, targetAssembly, defaultStyleKey, out auxillaryResources); isThemeStyle = currentStyle != null; } else { object resource = this.SceneViewModel.FindResource(defaultStyleKey); if (resource == null) { return; } if (projectContext1 != null && projectContext1.IsCapabilitySet(PlatformCapability.VsmInToolkit) && (projectContext1.IsCapabilitySet(PlatformCapability.SupportsVisualStateManager) && projectContext1.PlatformMetadata.IsNullType((ITypeId)projectContext1.ResolveType(ProjectNeutralTypes.VisualStateManager)))) { IAssembly usingAssemblyName = projectContext1.Platform.Metadata.GetPlatformAssemblyUsingAssemblyName(targetElement.Type.RuntimeAssembly); if (usingAssemblyName == null || !AssemblyHelper.IsPlatformAssembly(usingAssemblyName)) { IDocumentContext documentContext = (IDocumentContext) new DocumentContext((IProjectContext) new ToolkitProjectContext(projectContext1), ((DocumentContext)this.SceneViewModel.Document.DocumentContext).DocumentLocator); DocumentNode node = documentContext.CreateNode(resource.GetType(), resource); if (ProjectAttributeHelper.GetDefaultStateRecords(this.Type, (ITypeResolver)(documentContext.TypeResolver as ProjectContext)).Count > 0 || (DocumentCompositeNode)node.FindFirst(new Predicate <DocumentNode>(this.SelectVisualStateGroupPredicate)) != null) { ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext1, this.DesignerContext.ViewUpdateManager); } } } SceneNode sceneNode = this.SceneViewModel.CreateSceneNode(resource); if (!PlatformTypes.Style.IsAssignableFrom((ITypeId)sceneNode.Type)) { return; } currentStyle = sceneNode.DocumentNode; } }