本文整理汇总了C#中System.Windows.FrameworkContentElement类的典型用法代码示例。如果您正苦于以下问题:C# FrameworkContentElement类的具体用法?C# FrameworkContentElement怎么用?C# FrameworkContentElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FrameworkContentElement类属于System.Windows命名空间,在下文中一共展示了FrameworkContentElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetItemsHost
/// <summary>
/// Sets the items host.
/// </summary>
/// <param name="element">The element.</param>
private static void SetItemsHost(FrameworkContentElement element)
{
var parent = element;
while (parent.Parent != null)
parent = (FrameworkContentElement) parent.Parent;
parent.SetValue(ItemsHostProperty, element);
}
示例2: FixupDataContext
/// <summary>
/// If you use a bindable flow document element more than once, you may encounter a "Collection was modified" exception.
/// The error occurs when the binding is updated because of a change to an inherited dependency property. The most common scenario
/// is when the inherited DataContext changes. It appears that an inherited properly like DataContext is propagated to its descendants.
/// When the enumeration of descendants gets to a BindableXXX, the dependency properties of that element change according to the new
/// DataContext, which change the (non-dependency) properties. However, for some reason, changing the flow content invalidates the
/// enumeration and raises an exception.
/// To work around this, one can either DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=FrameworkElement}}"
/// in code. This is clumsy, so every derived type calls this function instead (which performs the same thing).
/// See http://code.logos.com/blog/2008/01/data_binding_in_a_flowdocument.html
/// </summary>
/// <param name="element"></param>
public static void FixupDataContext(FrameworkContentElement element)
{
Binding b = new Binding(FrameworkContentElement.DataContextProperty.Name);
// another approach (if this one has problems) is to bind to an ancestor by ElementName
b.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FrameworkElement), 1);
element.SetBinding(FrameworkContentElement.DataContextProperty, b);
}
示例3: UpdateStyleCache
// ===========================================================================
// These methods are invoked when a Style/Template cache needs to be updated
// ===========================================================================
#region UpdateCache
//
// This method
// 1. Updates the style cache for the given fe/fce
//
internal static void UpdateStyleCache(
FrameworkElement fe,
FrameworkContentElement fce,
Style oldStyle,
Style newStyle,
ref Style styleCache)
{
Debug.Assert(fe != null || fce != null);
if (newStyle != null)
{
// We have a new style. Make sure it's targeting the right
// type, and then seal it.
DependencyObject d = fe;
if (d == null)
{
d = fce;
}
newStyle.CheckTargetType(d);
newStyle.Seal();
}
styleCache = newStyle;
// Do style property invalidations. Note that some of the invalidations may be callouts
// that could turn around and query the style property on this node. Hence it is essential
// to update the style cache before we do this operation.
StyleHelper.DoStyleInvalidations(fe, fce, oldStyle, newStyle);
// Now look for triggers that might want their EnterActions or ExitActions
// to run immediately.
StyleHelper.ExecuteOnApplyEnterExitActions(fe, fce, newStyle, StyleDataField);
}
示例4: FrameworkObject
// internal FrameworkObject(DependencyObject d, bool throwIfNeither)
// : this(d)
// {
// if (throwIfNeither && this._fe == null && this._fce == null)
// {
// object arg = (d != null) ? (object)d.GetType() : (object)"NULL";
// throw new InvalidOperationException(System.Windows.SR.Get(SRID.MustBeFrameworkDerived, arg));
// }
// }
internal FrameworkObject(FrameworkElement frameworkElement, FrameworkContentElement frameworkContentElement)
{
this.frameworkElement = frameworkElement;
this.frameworkContentElement = frameworkContentElement;
if (frameworkElement != null)
{
this.dependencyObject = frameworkElement;
}
else
{
this.dependencyObject = frameworkContentElement;
}
}
示例5: GetBlockCollection
public static BlockCollection GetBlockCollection(FrameworkContentElement elem)
{
if (elem == null) return null;
var propInfo = elem.GetType().GetProperty("Blocks");
if (propInfo == null) return null;
if (propInfo.CanRead && propInfo.PropertyType==typeof(BlockCollection))
{
return propInfo.GetValue(elem, null) as BlockCollection;
}
if (elem is FlowDocument) return ((FlowDocument)elem).Blocks;
if (elem is Section) return ((Section)elem).Blocks;
if (elem is ListItem) return ((ListItem)elem).Blocks;
if (elem is TableCell) return ((TableCell)elem).Blocks;
return null;
}
示例6: NewNodeEndInit
/// <summary>
/// Call EndInit on the newly-created node to fire the
/// "Initialized" event.
/// </summary>
private static void NewNodeEndInit( bool treeNodeIsFE,
FrameworkElement treeNodeFE, FrameworkContentElement treeNodeFCE )
{
if( treeNodeIsFE )
{
// Mark the beginning of the initialization phase
treeNodeFE.EndInit();
}
else
{
// Mark the beginning of the initialization phase
treeNodeFCE.EndInit();
}
}
示例7: RemoveSections
public static void RemoveSections(FrameworkContentElement elem)
{
var blocks = GetBlockCollection(elem);
if (blocks!=null) foreach (var b in new List<Block>(blocks)) RemoveSections(b);
if (elem is Section)
{
var sec = elem as Section;
var parentBlocks = GetBlockCollection(sec.Parent as FrameworkContentElement);
if (parentBlocks==null) return;
while (sec.Blocks.Count>0)
{
var block = sec.Blocks.FirstBlock;
sec.Blocks.Remove(block);
parentBlocks.InsertBefore(sec, block);
}
parentBlocks.Remove(sec);
}
}
示例8: ClearTags
public void ClearTags(FrameworkContentElement elem)
{
elem.Tag = DependencyProperty.UnsetValue;
foreach (var e in LogicalTreeHelper.GetChildren(elem).OfType<FrameworkContentElement>()) ClearTags(e);
}
示例9: FindImplicitStyleResource
// FindImplicitSytle(fce) : Default: unlinkedParent, deferReference
internal static object FindImplicitStyleResource(FrameworkContentElement fce, object resourceKey, out object source)
{
// Do a FindResource call only if someone in the ancestry has
// implicit styles. This is a performance optimization.
if (fce.ShouldLookupImplicitStyles)
{
object unlinkedParent = null;
bool allowDeferredResourceReference = false;
bool mustReturnDeferredResourceReference = false;
// Implicit style lookup must stop at the app.
bool isImplicitStyleLookup = true;
// For non-controls the implicit StyleResource lookup must stop at
// the templated parent. Look at task 25606 for further details.
DependencyObject boundaryElement = fce.TemplatedParent;
object implicitStyle = FindResourceInternal(null, fce, FrameworkContentElement.StyleProperty, resourceKey, unlinkedParent, allowDeferredResourceReference, mustReturnDeferredResourceReference, boundaryElement, isImplicitStyleLookup, out source);
// Look at comments on the FE version of this method.
// Debug.Assert(!(implicitStyle != DependencyProperty.UnsetValue && fce.ShouldLookupImplicitStyles == false),
// "ShouldLookupImplicitStyles is false even while there exists an implicit style in the lookup path. To be precise at source " + source);
return implicitStyle;
}
source = null;
return DependencyProperty.UnsetValue;
}
示例10: AddStyleHandlersToEventRoute
// Add Style TargetType and FEF EventHandlers to the EventRoute
internal static void AddStyleHandlersToEventRoute(
FrameworkElement fe,
FrameworkContentElement fce,
EventRoute route,
RoutedEventArgs args)
{
Debug.Assert(fe != null || fce != null);
DependencyObject source = (fe != null) ? (DependencyObject)fe : (DependencyObject)fce;
Style selfStyle = null;
FrameworkTemplate selfFrameworkTemplate = null;
DependencyObject templatedParent = null;
int templateChildIndex = -1;
// Fetch selfStyle, TemplatedParent and TemplateChildIndex
if (fe != null)
{
selfStyle = fe.Style;
selfFrameworkTemplate = fe.TemplateInternal;
templatedParent = fe.TemplatedParent;
templateChildIndex = fe.TemplateChildIndex;
}
else
{
selfStyle = fce.Style;
templatedParent = fce.TemplatedParent;
templateChildIndex = fce.TemplateChildIndex;
}
// Add TargetType EventHandlers to the route. Notice that ThemeStyle
// cannot have EventHandlers and hence are ignored here.
RoutedEventHandlerInfo[] handlers = null;
if (selfStyle != null && selfStyle.EventHandlersStore != null)
{
handlers = selfStyle.EventHandlersStore.GetRoutedEventHandlers(args.RoutedEvent);
AddStyleHandlersToEventRoute(route, source, handlers);
}
if (selfFrameworkTemplate != null && selfFrameworkTemplate.EventHandlersStore != null)
{
handlers = selfFrameworkTemplate.EventHandlersStore.GetRoutedEventHandlers(args.RoutedEvent);
AddStyleHandlersToEventRoute(route, source, handlers);
}
if (templatedParent != null)
{
FrameworkTemplate templatedParentTemplate = null;
FrameworkElement feTemplatedParent = templatedParent as FrameworkElement;
Debug.Assert( feTemplatedParent != null );
templatedParentTemplate = feTemplatedParent.TemplateInternal;
// Fetch handlers from either the parent style or template
handlers = null;
if (templatedParentTemplate != null && templatedParentTemplate.HasEventDependents)
{
handlers = StyleHelper.GetChildRoutedEventHandlers(templateChildIndex, args.RoutedEvent, ref templatedParentTemplate.EventDependents);
}
// Add FEF EventHandlers to the route
AddStyleHandlersToEventRoute(route, source, handlers);
}
}
示例11: InvalidateOnResourcesChange
/// <summary>
/// Invalidates all the properties on the nodes in the given sub-tree
/// that are referring to the resource[s] that are changing.
/// </summary>
internal static void InvalidateOnResourcesChange(
FrameworkElement fe,
FrameworkContentElement fce,
ResourcesChangeInfo info)
{
Debug.Assert(fe != null || fce != null, "Node with the resources change notification must be an FE or an FCE.");
// We're interested in changes to the Template property that occur during
// the walk - if the template has changed we don't need to invalidate
// template-driven properties a second time. The HasTemplateChanged property
// is cleared on the first visit to each node, so that it means "template
// changed during the walk". But one relevant node isn't visited during
// the walk - the templated parent of the initial node. So we handle that now.
FrameworkObject fo = new FrameworkObject(fe, fce);
fo.Reset(fo.TemplatedParent);
fo.HasTemplateChanged = false;
DependencyObject d = (fe != null) ? (DependencyObject)fe : (DependencyObject)fce;
if (HasChildren(fe, fce))
{
// Spin up a DescendentsWalker only when
// the current node has children to walk
DescendentsWalker<ResourcesChangeInfo> walker = new DescendentsWalker<ResourcesChangeInfo>(
TreeWalkPriority.LogicalTree, ResourcesChangeDelegate, info);
walker.StartWalk(d);
}
else
{
// Degenerate case when the current node is a leaf node and has no children.
OnResourcesChanged(d, info, true);
}
}
示例12: Invoke
/// <summary>
/// Invoke the SoundPlayer action.
/// </summary>
internal sealed override void Invoke(FrameworkElement el,
FrameworkContentElement ctntEl,
Style targetStyle,
FrameworkTemplate targetTemplate,
Int64 layer)
{
PlayWhenLoaded();
}
示例13: HasChildren
/// <summary>
/// Says if the current FE or FCE has visual or logical children
/// </summary>
internal static bool HasChildren(FrameworkElement fe, FrameworkContentElement fce)
{
// See if we have logical or visual children, in which case this is a real tree invalidation.
return ( (fe != null && (fe.HasLogicalChildren ||
fe.HasVisualChildren ||
(Popup.RegisteredPopupsField.GetValue(fe) != null)
)
) ||
(fce != null && fce.HasLogicalChildren)
);
}
示例14: InvalidateTreeDependentProperties
/// <summary>
/// Invalidate all the properties in the given
/// collection of inheritable properties
/// </summary>
/// <remarks>
/// This method is called during an [FE/FCE].OnAncestorChange
/// </remarks>
internal static FrugalObjectList<DependencyProperty> InvalidateTreeDependentProperties(
TreeChangeInfo info,
FrameworkElement fe,
FrameworkContentElement fce,
Style selfStyle,
Style selfThemeStyle,
ref ChildRecord childRecord,
bool isChildRecordValid,
bool hasStyleChanged,
bool isSelfInheritanceParent)
{
Debug.Assert(fe != null || fce != null, "Must have non-null current node");
DependencyObject d = fe != null ? (DependencyObject)fe : (DependencyObject)fce;
FrameworkObject fo = new FrameworkObject(fe, fce);
// Pull up the parent's InheritableProperties cache
FrugalObjectList<DependencyProperty> parentInheritableProperties = info.InheritablePropertiesStack.Peek();
// Loop through all cached inheritable
// to see if they should be invalidated.
int inheritablePropertiesCount = parentInheritableProperties != null ? parentInheritableProperties.Count : 0;
FrugalObjectList<DependencyProperty> currentInheritableProperties = null;
if (HasChildren(fe, fce))
{
currentInheritableProperties = new FrugalObjectList<DependencyProperty>(inheritablePropertiesCount);
}
info.ResetInheritableValueIndexer();
for (int i = 0; i < inheritablePropertiesCount; i++)
{
DependencyProperty inheritableProperty = parentInheritableProperties[i];
Debug.Assert(inheritableProperty.IsPotentiallyInherited, "if we got here, it means that this property is inheritable by someone");
PropertyMetadata metadata = inheritableProperty.GetMetadata(d);
// Invalidate only properties that are marked as inheritable.
// These are the ones that will be affected by an ancestor changes.
if (metadata.IsInherited)
{
FrameworkPropertyMetadata fMetadata = (FrameworkPropertyMetadata)metadata;
bool changed = InvalidateTreeDependentProperty(info, d, ref fo, inheritableProperty, fMetadata,
selfStyle, selfThemeStyle, ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent);
// If a change is detected then add the inheritable property to
// the current list so that it can be used to invalidate further children
if (changed && currentInheritableProperties != null)
{
Debug.Assert(!currentInheritableProperties.Contains(inheritableProperty), "InheritableProperties list should not have duplicates");
// Children do not need to inherit properties across a tree boundary
// unless the property is set to override this behavior.
if (!SkipNow(fo.InheritanceBehavior) || fMetadata.OverridesInheritanceBehavior)
{
currentInheritableProperties.Add(inheritableProperty);
}
}
}
}
return currentInheritableProperties;
}
示例15: FrameworkObject
internal FrameworkObject(FrameworkElement fe, FrameworkContentElement fce)
{
_fe = fe;
_fce = fce;
if (fe != null)
_do = fe;
else
_do = fce;
}