// Given a multi data trigger and associated context information,
        //  evaluate the old and new states of the trigger.

        // The short-circuit logic of multi property trigger applies here too.
        //  we bail if any of the "other" conditions evaluate to false.
        private static void EvaluateOldNewStates( MultiDataTrigger multiDataTrigger,
            DependencyObject triggerContainer,
            BindingBase binding, BindingValueChangedEventArgs changedArgs, UncommonField<HybridDictionary[]> dataField,
            Style style, FrameworkTemplate frameworkTemplate,
            out bool oldState, out bool newState )
        {
            BindingBase evaluationBinding = null;
            object  evaluationValue = null;
            TriggerCondition[] conditions = multiDataTrigger.TriggerConditions;

            // Set up the default condition: A trigger with no conditions will never evaluate to true.
            oldState = false;
            newState = false;

            for( int i = 0; i < multiDataTrigger.Conditions.Count; i++ )
            {
                evaluationBinding = conditions[i].Binding;

                Debug.Assert( evaluationBinding != null,
                    "A null binding was encountered in a MultiDataTrigger conditions collection - this is invalid input and should have been caught earlier.");

                if( evaluationBinding == binding )
                {
                    // The binding that changed belonged to the current condition.
                    oldState = conditions[i].ConvertAndMatch(changedArgs.OldValue);
                    newState = conditions[i].ConvertAndMatch(changedArgs.NewValue);

                    if( oldState == newState )
                    {
                        // There couldn't possibly be a transition here, abort.  The
                        //  returned values here aren't necessarily the state of the
                        //  triggers, but we only care about a transition today.  If
                        //  we care about actual values, we'll need to continue evaluation.
                        return;
                    }
                }
                else
                {
                    evaluationValue = GetDataTriggerValue(dataField, triggerContainer, evaluationBinding);
                    if( !conditions[i].ConvertAndMatch(evaluationValue) )
                    {
                        // A condition other than the one changed has evaluated to false.
                        // There couldn't possibly be a transition here, short-circuit and abort.
                        oldState = false;
                        newState = false;
                        return;
                    }
                }
            }

            // We should only get this far only if the binding change causes
            //  a true->false (or vice versa) transition in one of the conditions,
            // AND that every other condition evaluated to true.
            return;
        }
        // Token: 0x06000313 RID: 787 RVA: 0x00008A44 File Offset: 0x00006C44
        internal static FrameworkElementFactory GetFEFTreeRoot(DependencyObject templatedParent)
        {
            FrameworkObject   frameworkObject  = new FrameworkObject(templatedParent, true);
            FrameworkTemplate templateInternal = frameworkObject.FE.TemplateInternal;

            return(templateInternal.VisualTree);
        }
 // Token: 0x0600068F RID: 1679 RVA: 0x00014729 File Offset: 0x00012929
 internal void Seal(FrameworkTemplate ownerTemplate)
 {
     if (this._sealed)
     {
         return;
     }
     this._frameworkTemplate = ownerTemplate;
     this.Seal();
 }
        /// <summary>
        ///     Check if the Framework Element Factory that produced the Template
        ///    that created this control has a Loaded Change Handler.
        /// </summary>
        /// <param name="templatedParent">
        ///     The caller must pass in a non-null templatedParent.
        /// </param>
        internal static FrameworkElementFactory GetFEFTreeRoot(DependencyObject templatedParent)
        {
            FrameworkObject fo = new FrameworkObject(templatedParent, true);

            Debug.Assert(fo.IsFE);

            FrameworkTemplate       templatedParentTemplate = fo.FE.TemplateInternal;
            FrameworkElementFactory fefTree = templatedParentTemplate.VisualTree;

            return(fefTree);
        }
Beispiel #5
0
		internal XamlContext (XamlContext parent, List<DependencyObject> resources, FrameworkTemplate template)
		{
			Parent = parent;
			Resources = resources;
			Template = template;

			//
			// Its just not worth the lookup time to try accessing these on the parents, so copy them over.
			//
			DefaultXmlns = parent.DefaultXmlns;
			IgnorableXmlns = new List<string> (parent.IgnorableXmlns);
			Xmlns = new Dictionary<string,string> (parent.Xmlns);
		}
Beispiel #6
0
        internal TemplateNameScope(
            DependencyObject templatedParent,
            List <DependencyObject> affectedChildren,
            FrameworkTemplate frameworkTemplate)
        {
            Debug.Assert(templatedParent == null || (templatedParent is FrameworkElement || templatedParent is FrameworkContentElement),
                         "Templates are only supported on FE/FCE containers.");

            _affectedChildren = affectedChildren;

            _frameworkTemplate = frameworkTemplate;

            _templatedParent = templatedParent;

            _isTemplatedParentAnFE = true;
        }
Beispiel #7
0
        internal TemplateNameScope(
                                    DependencyObject templatedParent,
                                    List<DependencyObject> affectedChildren,
                                    FrameworkTemplate frameworkTemplate )
        {
            Debug.Assert(templatedParent == null || (templatedParent is FrameworkElement || templatedParent is FrameworkContentElement),
                         "Templates are only supported on FE/FCE containers.");

            _affectedChildren = affectedChildren;

            _frameworkTemplate = frameworkTemplate;

            _templatedParent = templatedParent;

            _isTemplatedParentAnFE = true;

        }
Beispiel #8
0
 void Dump(FrameworkTemplate template)
 {
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Indent = true;
     settings.IndentChars = new string(' ', 4);
     settings.NewLineOnAttributes = true;
     StringBuilder strBuild = new StringBuilder();
     XmlWriter xmlWrite = XmlWriter.Create(strBuild, settings);
     try
     {
         XamlWriter.Save(template, xmlWrite);
         txtBox.Text = strBuild.ToString();
     }
     catch (Exception e)
     {
         txtBox.Text = e.Message;
     }
 }
Beispiel #9
0
    void ShowTemplate(System.Windows.Forms.WebBrowser browser, FrameworkTemplate template) {
      if( template == null ) {
        browser.DocumentText = "(no template)";
        return;
      }

      // Write the template to a file so that the browser knows to show it as XML
      string filename = System.IO.Path.GetTempFileName();
      File.Delete(filename);
      filename = System.IO.Path.ChangeExtension(filename, "xml");

      // pretty print the XAML (for View Source)
      using( XmlTextWriter writer = new XmlTextWriter(filename, System.Text.Encoding.UTF8) ) {
        writer.Formatting = Formatting.Indented;
        XamlWriter.Save(template, writer);
      }

      // Show the template
      browser.Navigate(new Uri(@"file:///" + filename));
    }
Beispiel #10
0
 internal static void UpdateTemplateCache(ContentPresenter contentPresenter, FrameworkTemplate frameworkTemplate1, FrameworkTemplate frameworkTemplate2, DependencyProperty dependencyProperty)
 {
     // throw new NotImplementedException();
 }
Beispiel #11
0
 /// <summary>
 ///     Called when all conditions have been satisfied for this action to be
 /// invoked.  (Conditions are not described on this TriggerAction object,
 /// but on the Trigger object holding it.)
 /// </summary>
 /// <remarks>
 ///     This variant is called when the Trigger lives in a Style, and
 /// hence given a reference to its corresponding Style object.
 /// </remarks>
 internal abstract void Invoke(FrameworkElement fe,
                               FrameworkContentElement fce,
                               Style targetStyle,
                               FrameworkTemplate targetTemplate,
                               Int64 layer);
Beispiel #12
0
        internal override void OnTemplateChangedInternal(FrameworkTemplate oldTemplate, FrameworkTemplate newTemplate) 
        {
            base.OnTemplateChangedInternal(oldTemplate, newTemplate);

            // This is called when a template is applied but before the new template has been inflated. 

            // If we had a style before, detach from event handlers 
            if (EditableTextBoxSite != null) 
            {
                EditableTextBoxSite.TextChanged -= new TextChangedEventHandler(OnEditableTextBoxTextChanged); 
                EditableTextBoxSite.SelectionChanged -= new RoutedEventHandler(OnEditableTextBoxSelectionChanged);
            }
        }
Beispiel #13
0
        //+----------------------------------------------------------------------------------------------------------------
        //
        //  SetTemplateParentValues
        //
        //  This method takes the "template parent values" (those that look like local values in the template), which
        //  are ordinarily shared, and sets them as local values on the FE/FCE that was just created.  This is used
        //  during serialization.
        //
        //+----------------------------------------------------------------------------------------------------------------

        private void SetTemplateParentValues(string name, object element)
        {
            FrameworkTemplate.SetTemplateParentValues(name, element, _frameworkTemplate, ref _provideValueServiceProvider);
        }
Beispiel #14
0
        //+----------------------------------------------------------------------------------------------------------------
        //
        //  SetTemplateParentValues
        //
        //  This method takes the "template parent values" (those that look like local values in the template), which
        //  are ordinarily shared, and sets them as local values on the FE/FCE that was just created.  This is used
        //  during serialization.
        //
        //+----------------------------------------------------------------------------------------------------------------

        internal static void SetTemplateParentValues(
                                                          string name,
                                                          object element,
                                                          FrameworkTemplate frameworkTemplate,
                                                          ref ProvideValueServiceProvider provideValueServiceProvider)
        {
            int childIndex;

            // Loop through the shared values, and set them onto the element.

            FrugalStructList<ChildRecord> childRecordFromChildIndex;
            HybridDictionary childIndexFromChildName;

            // Seal the template, and get the name->index and index->ChildRecord mappings

            if (!frameworkTemplate.IsSealed)
            {
                frameworkTemplate.Seal();
            }

            childIndexFromChildName = frameworkTemplate.ChildIndexFromChildName;
            childRecordFromChildIndex = frameworkTemplate.ChildRecordFromChildIndex;


            // Calculate the child index

            childIndex = StyleHelper.QueryChildIndexFromChildName(name, childIndexFromChildName);

            // Do we have a ChildRecord for this index (i.e., there's some property set on it)?

            if (childIndex < childRecordFromChildIndex.Count)
            {
                // Yes, get the record.

                ChildRecord child = (ChildRecord)childRecordFromChildIndex[childIndex];

                // Loop through the properties which are in some way set on this child

                for (int i = 0; i < child.ValueLookupListFromProperty.Count; i++)
                {
                    // And for each of those properties, loop through the potential values specified in the template
                    // for that property on that child.

                    for (int j = 0; j < child.ValueLookupListFromProperty.Entries[i].Value.Count; j++)
                    {
                        // Get this value (in valueLookup)

                        ChildValueLookup valueLookup;
                        valueLookup = (ChildValueLookup)child.ValueLookupListFromProperty.Entries[i].Value.List[j];

                        // See if this value is one that is considered to be locally set on the child element

                        if (valueLookup.LookupType == ValueLookupType.Simple
                            ||
                            valueLookup.LookupType == ValueLookupType.Resource
                            ||
                            valueLookup.LookupType == ValueLookupType.TemplateBinding)
                        {

                            // This shared value is for this element, so we'll set it.

                            object value = valueLookup.Value;

                            // If this is a TemplateBinding, put on an expression for it, so that it can
                            // be represented correctly (e.g. for serialization).  Otherwise, keep it as an ME.

                            if (valueLookup.LookupType == ValueLookupType.TemplateBinding)
                            {
                                value = new TemplateBindingExpression(value as TemplateBindingExtension);

                            }

                            // Dynamic resources need to be converted to an expression also.

                            else if (valueLookup.LookupType == ValueLookupType.Resource)
                            {
                                value = new ResourceReferenceExpression(value);
                            }

                            // Bindings are handled as just an ME

                            // Set the value directly onto the element.

                            MarkupExtension me = value as MarkupExtension;

                            if (me != null)
                            {
                                // This is provided for completeness, but really there's only a few
                                // MEs that survive TemplateBamlRecordReader.  E.g. NullExtension would
                                // have been converted to a null by now.  There's only a few MEs that
                                // are preserved, e.g. Binding and DynamicResource.  Other MEs, such as
                                // StaticResource, wouldn't be able to ProvideValue here, because we don't
                                // have a ParserContext.

                                if (provideValueServiceProvider == null)
                                {
                                    provideValueServiceProvider = new ProvideValueServiceProvider();
                                }

                                provideValueServiceProvider.SetData(element, valueLookup.Property);
                                value = me.ProvideValue(provideValueServiceProvider);
                                provideValueServiceProvider.ClearData();
                            }

                            (element as DependencyObject).SetValue(valueLookup.Property, value); //sharedDp.Dp, value );

                        }
                    }
                }
            }
        }
Beispiel #15
0
		private XamlContext CreateXamlContext (FrameworkTemplate template)
		{
			return new XamlContext (Context, CreateResourcesList (), template);
		}
        // Seal this FEF
        internal void Seal(FrameworkTemplate ownerTemplate)
        {
            if (_sealed)
            {
                return;
            }

            // Store owner Template
            _frameworkTemplate = ownerTemplate;

            // Perform actual Seal operation
            Seal();
        }
Beispiel #17
0
		private XamlContext CreateXamlContext (FrameworkTemplate template)
		{
			return new XamlContext (Context, TopElement, CreateResourcesList (), template, reader);
		}
Beispiel #18
0
 // Token: 0x06000C1B RID: 3099 RVA: 0x0002D285 File Offset: 0x0002B485
 internal TemplateNameScope(DependencyObject templatedParent, List <DependencyObject> affectedChildren, FrameworkTemplate frameworkTemplate)
 {
     this._affectedChildren      = affectedChildren;
     this._frameworkTemplate     = frameworkTemplate;
     this._templatedParent       = templatedParent;
     this._isTemplatedParentAnFE = true;
 }
Beispiel #19
0
		internal XamlContext (XamlContext parent, object top_element,
							List<DependencyObject> resources,
							FrameworkTemplate template, XamlNode node)
		{
			Parent = parent;
			TopElement = top_element;
			Resources = resources;
			Template = template;
			Node = node;

			//
			// Its just not worth the lookup time to try accessing these on the parents, so copy them over.
			//
			XmlnsCachedTypes = new Dictionary<XmlNsKey, Type>();
		}
Beispiel #20
0
		internal XamlContext (XamlContext parent, List<DependencyObject> resources, FrameworkTemplate template)
		{
			Parent = parent;
			Resources = resources;
			Template = template;
		}
        //
        //  This method
        //  1. Adds shared table entries for property values set via Triggers
        //
        private static void ProcessTemplateTriggers(
            TriggerCollection                                           triggers,
            FrameworkTemplate                                           frameworkTemplate,
            ref FrugalStructList<ChildRecord>                           childRecordFromChildIndex,
            ref FrugalStructList<ItemStructMap<TriggerSourceRecord>>    triggerSourceRecordFromChildIndex,
            ref FrugalStructList<ContainerDependent>                    containerDependents,
            ref FrugalStructList<ChildPropertyDependent>                resourceDependents,
            ref ItemStructList<ChildEventDependent>                     eventDependents,
            ref HybridDictionary                                        dataTriggerRecordFromBinding,
            HybridDictionary                                            childIndexFromChildID,
            ref bool                                                    hasInstanceValues,
            ref HybridDictionary                                        triggerActions,
            FrameworkElementFactory                                     templateRoot,
            ref EventHandlersStore                                      eventHandlersStore,
            ref FrugalMap                                               propertyTriggersWithActions,
            ref HybridDictionary                                        dataTriggersWithActions,
            ref bool                                                    hasLoadedChangeHandler)
        {
            if (triggers != null)
            {
                int triggerCount = triggers.Count;
                for (int i = 0; i < triggerCount; i++)
                {
                    TriggerBase triggerBase = triggers[i];

                    Trigger trigger;
                    MultiTrigger multiTrigger;
                    DataTrigger dataTrigger;
                    MultiDataTrigger multiDataTrigger;
                    EventTrigger eventTrigger;

                    DetermineTriggerType( triggerBase, out trigger, out multiTrigger, out dataTrigger, out multiDataTrigger, out eventTrigger );

                    if ( trigger != null || multiTrigger != null||
                        dataTrigger != null || multiDataTrigger != null )
                    {
                        // Update the SourceChildIndex for each of the conditions for this trigger
                        TriggerCondition[] conditions = triggerBase.TriggerConditions;
                        for (int k=0; k<conditions.Length; k++)
                        {
                            conditions[k].SourceChildIndex = StyleHelper.QueryChildIndexFromChildName(conditions[k].SourceName, childIndexFromChildID);
                        }

                        // Set things up to handle Setter values
                        for (int j = 0; j < triggerBase.PropertyValues.Count; j++)
                        {
                            PropertyValue propertyValue = triggerBase.PropertyValues[j];

                            // Check for trigger rules that act on template children
                            if (propertyValue.ChildName == StyleHelper.SelfName)
                            {
                                // "Self" (container) trigger

                                // Track properties on the container that are being driven by
                                // the Template so that they can be invalidated during Template changes
                                StyleHelper.AddContainerDependent(propertyValue.Property, true /*fromVisualTrigger*/, ref containerDependents);
                            }

                            StyleHelper.UpdateTables(ref propertyValue, ref childRecordFromChildIndex,
                                ref triggerSourceRecordFromChildIndex, ref resourceDependents, ref dataTriggerRecordFromBinding,
                                childIndexFromChildID, ref hasInstanceValues);
                        }

                        // Set things up to handle TriggerActions
                        if( triggerBase.HasEnterActions || triggerBase.HasExitActions )
                        {
                            if( trigger != null )
                            {
                                StyleHelper.AddPropertyTriggerWithAction( triggerBase, trigger.Property, ref propertyTriggersWithActions );
                            }
                            else if( multiTrigger != null )
                            {
                                for( int k = 0; k < multiTrigger.Conditions.Count; k++ )
                                {
                                    Condition triggerCondition = multiTrigger.Conditions[k];

                                    StyleHelper.AddPropertyTriggerWithAction( triggerBase, triggerCondition.Property, ref propertyTriggersWithActions );
                                }
                            }
                            else if( dataTrigger != null )
                            {
                                StyleHelper.AddDataTriggerWithAction( triggerBase, dataTrigger.Binding, ref dataTriggersWithActions );
                            }
                            else if( multiDataTrigger != null )
                            {
                                for( int k = 0; k < multiDataTrigger.Conditions.Count; k++ )
                                {
                                    Condition dataCondition = multiDataTrigger.Conditions[k];

                                    StyleHelper.AddDataTriggerWithAction( triggerBase, dataCondition.Binding, ref dataTriggersWithActions );
                                }
                            }
                            else
                            {
                                throw new InvalidOperationException(SR.Get(SRID.UnsupportedTriggerInTemplate, triggerBase.GetType().Name));
                            }
                        }
                    }
                    else if( eventTrigger != null )
                    {
                        StyleHelper.ProcessEventTrigger(eventTrigger,
                                                        childIndexFromChildID,
                                                        ref triggerActions,
                                                        ref eventDependents,
                                                        templateRoot,
                                                        frameworkTemplate,
                                                        ref eventHandlersStore,
                                                        ref hasLoadedChangeHandler);
                    }
                    else
                    {
                        throw new InvalidOperationException(SR.Get(SRID.UnsupportedTriggerInTemplate, triggerBase.GetType().Name));
                    }
                }
            }
        }
        //+------------------------------------------------------------------------------------
        //
        //  FindNameInTemplateContent
        //
        //  Find the object in the template content with the specified name.  This looks
        //  both for children both that are optimized FE/FCE tyes, or any other type.
        //
        //+------------------------------------------------------------------------------------

        internal static Object FindNameInTemplateContent(
            DependencyObject    container,
            string              childName,
            FrameworkTemplate   frameworkTemplate)
        {
            Debug.Assert(frameworkTemplate != null );

            // First, look in the list of optimized FE/FCEs in this template for this name.

            int index;
            Debug.Assert(frameworkTemplate != null);
            index = StyleHelper.QueryChildIndexFromChildName(childName, frameworkTemplate.ChildIndexFromChildName);

            // Did we find it?
            if (index == -1)
            {
                // No, we didn't find it, look at the rest of the named elements in the template content.

                Hashtable hashtable = TemplatedNonFeChildrenField.GetValue(container);
                if( hashtable != null )
                {
                    return hashtable[childName];
                }

                return null;
            }
            else
            {
                // Yes, we found the FE/FCE, return it.

                return StyleHelper.GetChild(container, index);
            }
        }
        //  ===========================================================================
        //  These methods read some of per-instane Style/Template data
        //  ===========================================================================

        #region ReadInstanceData

        //
        //  This method
        //  1. Creates the ChildIndex for the given ChildName. If there is an
        //     existing childIndex it throws an exception for a duplicate name
        //
        internal static int CreateChildIndexFromChildName(
            string              childName,
            FrameworkTemplate   frameworkTemplate)
        {
            Debug.Assert(frameworkTemplate != null );

            // Lock must be made by caller

            HybridDictionary childIndexFromChildName;
            int lastChildIndex;

            Debug.Assert(frameworkTemplate != null);

            childIndexFromChildName = frameworkTemplate.ChildIndexFromChildName;
            lastChildIndex = frameworkTemplate.LastChildIndex;

            if (childIndexFromChildName.Contains(childName))
            {
                throw new ArgumentException(SR.Get(SRID.NameScopeDuplicateNamesNotAllowed, childName));
            }

            // Normal templated child check
            // If we're about to give out an index that we can't support, throw.
            if (lastChildIndex >= 0xFFFF)
            {
                throw new InvalidOperationException(SR.Get(SRID.StyleHasTooManyElements));
            }

            // No index found, allocate
            object value = lastChildIndex;

            childIndexFromChildName[childName] = value;

            Interlocked.Increment(ref lastChildIndex);

            Debug.Assert(frameworkTemplate != null);
            frameworkTemplate.LastChildIndex = lastChildIndex;

            return (int)value;
        }
        // Given a single data trigger and associated context information,
        //  evaluate the old and new states of the trigger.
        private static void EvaluateOldNewStates( DataTrigger dataTrigger,
            DependencyObject triggerContainer,
            BindingBase binding, BindingValueChangedEventArgs bindingChangedArgs, UncommonField<HybridDictionary[]> dataField,
            Style style, FrameworkTemplate frameworkTemplate,
            out bool oldState, out bool newState )
        {
            TriggerCondition[] conditions = dataTrigger.TriggerConditions;
            Debug.Assert( conditions != null && conditions.Length == 1,
                "This method assumes there is exactly one TriggerCondition." );

            oldState = conditions[0].ConvertAndMatch(bindingChangedArgs.OldValue);
            newState = conditions[0].ConvertAndMatch(bindingChangedArgs.NewValue);
        }
        private ContainerVisual GetHeaderFooterVisualFromDataTemplate(FrameworkTemplate template, Rect container)
        {
            if (template == null)
            {
                return null;
            }

            var doc = Source as PrintableDocument;

            var content = template.LoadContent() as FrameworkElement;
            content.DataContext = doc.DataContext;

            var width = _definition.PageSize.Width - _definition.Margins.Left - _definition.Margins.Right;

            content.Measure(_definition.PageSize);
            content.Arrange(new Rect(container.X, container.Y, width, content.DesiredSize.Height));
            content.UpdateLayout();

            var visual = new ContainerVisual();

            visual.Children.Add(content);

            return visual;
        }
Beispiel #26
0
        // Token: 0x06000C6B RID: 3179 RVA: 0x0002E8E0 File Offset: 0x0002CAE0
        private static void InvalidateStyleAndReferences(DependencyObject d, ResourcesChangeInfo info, bool containsTypeOfKey)
        {
            FrameworkObject frameworkObject = new FrameworkObject(d);

            if (frameworkObject.IsFE)
            {
                FrameworkElement fe = frameworkObject.FE;
                if (containsTypeOfKey && !info.IsThemeChange && (fe.HasImplicitStyleFromResources || fe.Style == FrameworkElement.StyleProperty.GetMetadata(fe.DependencyObjectType).DefaultValue))
                {
                    fe.UpdateStyleProperty();
                }
                if (fe.Style != null && fe.Style.HasResourceReferences && !fe.HasStyleChanged)
                {
                    StyleHelper.InvalidateResourceDependents(d, info, ref fe.Style.ResourceDependents, false);
                }
                if (fe.TemplateInternal != null && fe.TemplateInternal.HasContainerResourceReferences)
                {
                    StyleHelper.InvalidateResourceDependents(d, info, ref fe.TemplateInternal.ResourceDependents, false);
                }
                if (fe.TemplateChildIndex > 0)
                {
                    FrameworkElement  frameworkElement = (FrameworkElement)fe.TemplatedParent;
                    FrameworkTemplate templateInternal = frameworkElement.TemplateInternal;
                    if (!frameworkElement.HasTemplateChanged && templateInternal.HasChildResourceReferences)
                    {
                        StyleHelper.InvalidateResourceDependentsForChild(frameworkElement, fe, fe.TemplateChildIndex, info, templateInternal);
                    }
                }
                if (!info.IsThemeChange)
                {
                    Style themeStyle = fe.ThemeStyle;
                    if (themeStyle != null && themeStyle.HasResourceReferences && themeStyle != fe.Style)
                    {
                        StyleHelper.InvalidateResourceDependents(d, info, ref themeStyle.ResourceDependents, false);
                        return;
                    }
                }
            }
            else if (frameworkObject.IsFCE)
            {
                FrameworkContentElement fce = frameworkObject.FCE;
                if (containsTypeOfKey && !info.IsThemeChange && (fce.HasImplicitStyleFromResources || fce.Style == FrameworkContentElement.StyleProperty.GetMetadata(fce.DependencyObjectType).DefaultValue))
                {
                    fce.UpdateStyleProperty();
                }
                if (fce.Style != null && fce.Style.HasResourceReferences && !fce.HasStyleChanged)
                {
                    StyleHelper.InvalidateResourceDependents(d, info, ref fce.Style.ResourceDependents, true);
                }
                if (fce.TemplateChildIndex > 0)
                {
                    FrameworkElement  frameworkElement2 = (FrameworkElement)fce.TemplatedParent;
                    FrameworkTemplate templateInternal2 = frameworkElement2.TemplateInternal;
                    if (!frameworkElement2.HasTemplateChanged && templateInternal2.HasChildResourceReferences)
                    {
                        StyleHelper.InvalidateResourceDependentsForChild(frameworkElement2, fce, fce.TemplateChildIndex, info, templateInternal2);
                    }
                }
                if (!info.IsThemeChange)
                {
                    Style themeStyle2 = fce.ThemeStyle;
                    if (themeStyle2 != null && themeStyle2.HasResourceReferences && themeStyle2 != fce.Style)
                    {
                        StyleHelper.InvalidateResourceDependents(d, info, ref themeStyle2.ResourceDependents, false);
                    }
                }
            }
        }
        private Size GetModelContentSize(object dataModel, FrameworkTemplate modelTemplate, Size availableSize)
        {
            FrameworkElement content = null;

            if (modelTemplate == null)
            {
                return Size.Empty;
            }

            content = modelTemplate.LoadContent() as FrameworkElement;

            if (content == null)
            {
                return Size.Empty;
            }

            content.DataContext = dataModel;
            content.Measure(availableSize);

            return content.DesiredSize;
        }
 /// <summary>
 ///     Called when all conditions have been satisfied for this action to be
 /// invoked.  (Conditions are not described on this TriggerAction object,
 /// but on the Trigger object holding it.)
 /// </summary>
 /// <remarks>
 ///     This variant is called when the Trigger lives in a Style, and
 /// hence given a reference to its corresponding Style object.
 /// </remarks>
 internal abstract void Invoke( FrameworkElement fe,
                               FrameworkContentElement fce,
                               Style targetStyle,
                               FrameworkTemplate targetTemplate,
                               Int64 layer);
        // Given a multi property trigger and associated context information,
        //  evaluate the old and new states of the trigger.

        // Note that we can only have a transition only if every property other
        //  than the changed property is true.  If any of the other properties
        //  are false, then the state is false and we can't have a false->true
        //  transition.
        // Hence this evaluation short-circuits if any property evaluation
        //  (other than the one being compared) turns out false.
        private static void EvaluateOldNewStates( MultiTrigger multiTrigger,
            DependencyObject triggerContainer, DependencyProperty changedProperty, DependencyPropertyChangedEventArgs changedArgs,
            int sourceChildIndex, Style style, FrameworkTemplate frameworkTemplate,
            out bool oldState, out bool newState )
        {
            int triggerChildId = 0;
            DependencyObject evaluationNode = null;
            TriggerCondition[] conditions = multiTrigger.TriggerConditions;

            // Set up the default condition: A trigger with no conditions will never evaluate to true.
            oldState = false;
            newState = false;

            for( int i = 0; i < conditions.Length; i++ )
            {
                if( conditions[i].SourceChildIndex != 0 )
                {
                    Debug.Assert( frameworkTemplate != null,
                        "A trigger outside of a Template is not supposed to have a SourceName.  This should have been caught somewhere upstream, like in Style.Seal().");
                    triggerChildId = conditions[i].SourceChildIndex;
                    evaluationNode = GetChild(triggerContainer, triggerChildId);
                }
                else
                {
                    triggerChildId = 0;
                    evaluationNode = triggerContainer;
                }

                Debug.Assert(evaluationNode != null,
                    "Couldn't find the node corresponding to the ID and name given in the trigger.  This should have been caught somewhere upstream, like StyleHelper.SealTemplate()." );

                if( conditions[i].Property == changedProperty && triggerChildId == sourceChildIndex )
                {
                    // This is the property that changed, and on the object we
                    //  care about.  Evaluate states.- see if the condition
                    oldState = conditions[i].Match(changedArgs.OldValue);
                    newState = conditions[i].Match(changedArgs.NewValue);

                    if( oldState == newState )
                    {
                        // There couldn't possibly be a transition here, abort.  The
                        //  returned values here aren't necessarily the state of the
                        //  triggers, but we only care about a transition today.  If
                        //  we care about actual values, we'll need to continue evaluation.
                        return;
                    }
                }
                else
                {
                    object evaluationValue = evaluationNode.GetValue( conditions[i].Property );
                    if( !conditions[i].Match(evaluationValue) )
                    {
                        // A condition other than the one changed has evaluated to false.
                        // There couldn't possibly be a transition here, short-circuit and abort.
                        oldState = false;
                        newState = false;
                        return;
                    }
                }
            }

            // We should only get this far only if every property change causes
            //  a true->false (or vice versa) transition in one of the conditions,
            // AND that every other condition evaluated to true.
            return;
        }
 /// <summary>
 /// Invoke the SoundPlayer action.
 /// </summary>
 internal sealed override void Invoke(FrameworkElement el,
                                      FrameworkContentElement ctntEl,
                                      Style targetStyle,
                                      FrameworkTemplate targetTemplate,
                                      Int64 layer)
 {
     PlayWhenLoaded();
 }
        // Dump the template.
        void Dump(FrameworkTemplate template)
        {
            if (template != null)
            {
                // Dump the XAML into the TextBox.
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                settings.IndentChars = new string(' ', 4);
                settings.NewLineOnAttributes = true;

                StringBuilder strbuild = new StringBuilder();
                XmlWriter xmlwrite = XmlWriter.Create(strbuild, settings);

                try
                {
                    XamlWriter.Save(template, xmlwrite);
                    txtbox.Text = strbuild.ToString();
                }
                catch (Exception exc)
                {
                    txtbox.Text = exc.Message;
                }
            }
            else
                txtbox.Text = "no template";
        }
        // Given a single property trigger and associated context information,
        //  evaluate the old and new states of the trigger.
        private static void EvaluateOldNewStates( Trigger trigger,
            DependencyObject triggerContainer, DependencyProperty changedProperty, DependencyPropertyChangedEventArgs changedArgs,
            int sourceChildIndex, Style style, FrameworkTemplate frameworkTemplate,
            out bool oldState, out bool newState )
        {

            Debug.Assert( trigger.Property == changedProperty,
                "We're trying to evaluate the state of a Trigger based on a property that doesn't affect that trigger.  This is indicative of an error upstream, when setting up the [Style/Template].TriggersWithActions data structure." );

            int triggerChildId = 0;

            if( trigger.SourceName != null )
            {
                Debug.Assert( frameworkTemplate != null,
                    "A trigger outside of a Template is not supposed to have a SourceName.  This should have been caught somewhere upstream, like in Style.Seal().");
                triggerChildId = QueryChildIndexFromChildName(trigger.SourceName, frameworkTemplate.ChildIndexFromChildName);
            }

            if( triggerChildId == sourceChildIndex )
            {
                TriggerCondition[] conditions = trigger.TriggerConditions;
                Debug.Assert( conditions != null && conditions.Length == 1,
                    "This method assumes there is exactly one TriggerCondition." );

                oldState = conditions[0].Match(changedArgs.OldValue);
                newState = conditions[0].Match(changedArgs.NewValue);
            }
            else
            {
                // Property change did not occur on an object we care about -
                //  skip evaluation of property values.  The state values here
                //  are bogus.  This is OK today since we just care about transition
                //  states but if later on it actually matters what the values are
                //  then we need to evaluate state on the actual triggerChildId.
                // (The old/new values would be the same, naturally.)
                oldState = false;
                newState = false;
            }

            return;
        }
Beispiel #33
0
    /// <summary>
    ///     Called when it's time to execute this storyboard action
    /// </summary>

    internal sealed override void Invoke( FrameworkElement fe, FrameworkContentElement fce, Style targetStyle, FrameworkTemplate frameworkTemplate, Int64 layer )
    {
        Debug.Assert( fe != null || fce != null, "Caller of internal function failed to verify that we have a FE or FCE - we have neither." );

        INameScope nameScope = null;
        if( targetStyle != null )
        {
            nameScope = targetStyle;
        }
        else
        {
            Debug.Assert( frameworkTemplate != null );
            nameScope = frameworkTemplate;
        }


        Begin( (fe != null ) ? (DependencyObject)fe : (DependencyObject)fce, nameScope, layer );
    }
Beispiel #34
0
 // Internal helper so FrameworkElement could see call the template changed virtual
 internal override void OnTemplateChangedInternal(FrameworkTemplate oldTemplate, FrameworkTemplate newTemplate)
 {
     OnTemplateChanged((ControlTemplate)oldTemplate, (ControlTemplate)newTemplate);
 }
Beispiel #35
0
 // Internal so that StyleHelper could uniformly call the TemplateChanged 
 // virtual on any templated parent
 internal virtual void OnTemplateChangedInternal( 
     FrameworkTemplate oldTemplate, 
     FrameworkTemplate newTemplate)
 { 
     HasTemplateChanged = true;
 }
Beispiel #36
0
 internal static int CreateChildIndexFromChildName(string p, FrameworkTemplate frameworkTemplate)
 {
     throw new NotImplementedException();
 }
Beispiel #37
0
        internal override void OnTemplateChangedInternal(FrameworkTemplate oldTemplate, FrameworkTemplate newTemplate)
        {
            // Invalidate template references
            _toolBarPanel = null;
            _toolBarOverflowPanel = null;

            base.OnTemplateChangedInternal(oldTemplate, newTemplate);
        }
Beispiel #38
0
 public static object FindName(this FrameworkTemplate frameworkTemplate, string name, FrameworkElement templatedParent)
 {
     return(NameScope.GetNameScope(templatedParent.TemplateChild).FindName(name));
 }
        // Given a Style/Template and a Binding whose value has changed, look for
        //  any data triggers that have trigger actions (EnterAction/ExitAction)
        //  and see if any of those actions need to run as a response to this change.
        private static void InvokeApplicableDataTriggerActions(
            Style                               style,
            FrameworkTemplate                   frameworkTemplate,
            DependencyObject                    container,
            BindingBase                         binding,
            BindingValueChangedEventArgs        e,
            UncommonField<HybridDictionary[]>   dataField)
        {
            HybridDictionary dataTriggersWithActions;

            if( style != null )
            {
                dataTriggersWithActions = style.DataTriggersWithActions;
            }
            else if( frameworkTemplate != null )
            {
                dataTriggersWithActions = frameworkTemplate.DataTriggersWithActions;
            }
            else
            {
                dataTriggersWithActions = null;
            }

            if( dataTriggersWithActions != null )
            {
                object candidateTrigger = dataTriggersWithActions[binding];

                if( candidateTrigger != null )
                {
                    // One or more trigger objects need to be evaluated.  The candidateTrigger
                    //  object may be a single trigger or a collection of them.
                    TriggerBase triggerBase = candidateTrigger as TriggerBase;
                    if( triggerBase != null )
                    {
                        InvokeDataTriggerActions( triggerBase, container, binding, e,
                            style, frameworkTemplate, dataField);
                    }
                    else
                    {
                        Debug.Assert(candidateTrigger is List<TriggerBase>, "Internal data structure error: The HybridDictionary [Style/Template].DataTriggersWithActions " +
                            "is expected to hold a single TriggerBase or a List<T> of them.  An object of type " +
                            candidateTrigger.GetType().ToString() + " is not expected.  Where did this object come from?");

                        List<TriggerBase> triggerList = (List<TriggerBase>)candidateTrigger;

                        for( int i = 0; i < triggerList.Count; i++ )
                        {
                            InvokeDataTriggerActions( triggerList[i], container, binding, e,
                                style, frameworkTemplate, dataField);
                        }
                    }
                }
            }
        }