本文整理汇总了C#中DependencyObject.ReadLocalValue方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.ReadLocalValue方法的具体用法?C# DependencyObject.ReadLocalValue怎么用?C# DependencyObject.ReadLocalValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.ReadLocalValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsDataBound
/// <summary>
/// Returns a value that indicates whether the specified property is currently data-bound.
/// </summary>
/// <param name="target">The object where <paramref name="property"/> is.</param>
/// <param name="property">The dependency property to check.</param>
/// <returns>True if the specified property is data-bound, otherwise False.</returns>
public static bool IsDataBound(DependencyObject target, DependencyProperty property)
{
#if NETFX_CORE
return target.ReadLocalValue(property) is BindingExpressionBase;
#else
return BindingOperations.IsDataBound(target, property);
#endif
}
示例2: RefreshBinding
/// <summary>
/// Force a data transfer from Binding source to target.
/// </summary>
/// <param name="target">The object where <paramref name="property"/> is.</param>
/// <param name="property">The dependency property to refresh.</param>
public static void RefreshBinding(DependencyObject target, DependencyProperty property)
{
#if NETFX_CORE
var bindingExpression = target.ReadLocalValue(property) as BindingExpression;
if (bindingExpression == null || bindingExpression.ParentBinding == null) return;
BindingOperations.SetBinding(target, property, bindingExpression.ParentBinding);
#else
var bindingExpressionBase = BindingOperations.GetBindingExpressionBase(target, property);
if (bindingExpressionBase == null) return;
bindingExpressionBase.UpdateTarget();
#endif
}
示例3: ItemFromContainer
/// <summary>
/// Return the item corresponding to the given UI element.
/// If the element was not generated as a container for this generator's
/// host, the method returns DependencyProperty.UnsetValue.
/// </summary>
public object ItemFromContainer(DependencyObject container)
{
if (container == null)
throw new ArgumentNullException("container");
object item = container.ReadLocalValue(ItemForItemContainerProperty);
if (item != DependencyProperty.UnsetValue)
{
// verify that the element really belongs to the host
if (!Host.IsHostForItemContainer(container))
item = DependencyProperty.UnsetValue;
}
return item;
}
示例4:
/// <summary>
/// Prepare the given element to act as the container for the
/// corresponding item. This includes applying the container style,
/// forwarding information from the host control (ItemTemplate, etc.),
/// and other small adjustments.
/// </summary>
/// <remarks>
/// This method must be called after the element has been added to the
/// visual tree, so that resource references and inherited properties
/// work correctly.
/// </remarks>
/// <param name="container"> The container to prepare.
/// Normally this is the result of the previous call to GenerateNext.
/// </param>
void IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
{
object item = container.ReadLocalValue(ItemForItemContainerProperty);
Host.PrepareItemContainer(container, item);
}
示例5: WriteInheritablePropertiesForFlowDocument
private static void WriteInheritablePropertiesForFlowDocument(DependencyObject context, XmlWriter xmlWriter, DependencyObject complexProperties)
{
DependencyProperty[] inheritableProperties = TextSchema.GetInheritableProperties(typeof(FlowDocument));
for (int i = 0; i < inheritableProperties.Length; i++)
{
DependencyProperty property = inheritableProperties[i];
object value = context.ReadLocalValue(property);
if (value != DependencyProperty.UnsetValue)
{
string stringValue = DPTypeDescriptorContext.GetStringValue(property, value);
if (stringValue != null)
{
stringValue = FilterNaNStringValueForDoublePropertyType(stringValue, property.PropertyType);
string propertyName;
if (property == FrameworkContentElement.LanguageProperty)
{
// Special case for CultureInfo property that must be represented in xaml as xml:lang attribute
propertyName = "xml:lang";
}
else
{
// Regular case using own property name
propertyName = property.OwnerType == typeof(Typography) ? "Typography." + property.Name : property.Name;
}
xmlWriter.WriteAttributeString(propertyName, stringValue);
}
else
{
complexProperties.SetValue(property, value);
}
}
}
}
示例6: WriteXamlAtomicElement
// Serializes an element assuming that it does not have any children. Used for TableColumn
//
private static void WriteXamlAtomicElement(DependencyObject element, XmlWriter xmlWriter, bool reduceElement)
{
Type elementTypeStandardized = TextSchema.GetStandardElementType(element.GetType(), reduceElement);
DependencyProperty[] elementProperties = TextSchema.GetNoninheritableProperties(elementTypeStandardized);
xmlWriter.WriteStartElement(elementTypeStandardized.Name);
for (int i = 0; i < elementProperties.Length; i++)
{
DependencyProperty property = elementProperties[i];
object propertyValue = element.ReadLocalValue(property);
if (propertyValue != null && propertyValue != DependencyProperty.UnsetValue)
{
System.ComponentModel.TypeConverter typeConverter = System.ComponentModel.TypeDescriptor.GetConverter(property.PropertyType);
Invariant.Assert(typeConverter != null, "typeConverter==null: is not expected for atomic elements");
Invariant.Assert(typeConverter.CanConvertTo(typeof(string)), "type is expected to be convertable into string type");
string stringValue = (string)typeConverter.ConvertTo(/*ITypeDescriptorContext:*/null, CultureInfo.InvariantCulture, propertyValue, typeof(string));
Invariant.Assert(stringValue != null, "expecting non-null stringValue");
xmlWriter.WriteAttributeString(property.Name, stringValue);
}
}
xmlWriter.WriteEndElement();
}
示例7: SpringloadCurrentFormatting
private void SpringloadCurrentFormatting(DependencyObject parent)
{
// Create new bag for formatting properties
_springloadFormatting = new DependencyObject();
// Check if we have an object to read from
if (parent == null)
{
return;
}
DependencyProperty[] inheritableProperties = TextSchema.GetInheritableProperties(typeof(Inline));
DependencyProperty[] noninheritableProperties = TextSchema.GetNoninheritableProperties(typeof(Span));
// Walk up the tree. At each step, if the element is typographical only,
// grab all non-inherited values. When we reach the top of the tree, grab all
// values.
DependencyObject element = parent;
while (element is Inline)
{
TextElementEditingBehaviorAttribute att = (TextElementEditingBehaviorAttribute)Attribute.GetCustomAttribute(element.GetType(), typeof(TextElementEditingBehaviorAttribute));
if (att.IsTypographicOnly)
{
for (int i = 0; i < inheritableProperties.Length; i++)
{
if (_springloadFormatting.ReadLocalValue(inheritableProperties[i]) == DependencyProperty.UnsetValue &&
inheritableProperties[i] != FrameworkElement.LanguageProperty &&
inheritableProperties[i] != FrameworkElement.FlowDirectionProperty &&
System.Windows.DependencyPropertyHelper.GetValueSource(element, inheritableProperties[i]).BaseValueSource != BaseValueSource.Inherited)
{
object value = parent.GetValue(inheritableProperties[i]);
_springloadFormatting.SetValue(inheritableProperties[i], value);
}
}
for (int i = 0; i < noninheritableProperties.Length; i++)
{
if (_springloadFormatting.ReadLocalValue(noninheritableProperties[i]) == DependencyProperty.UnsetValue &&
noninheritableProperties[i] != TextElement.TextEffectsProperty &&
System.Windows.DependencyPropertyHelper.GetValueSource(element, noninheritableProperties[i]).BaseValueSource != BaseValueSource.Inherited)
{
object value = parent.GetValue(noninheritableProperties[i]);
_springloadFormatting.SetValue(noninheritableProperties[i], value);
}
}
}
element = ((TextElement)element).Parent;
}
}
示例8: GetItemFromContainer
private object GetItemFromContainer(DependencyObject container)
{
return container.ReadLocalValue(System.Windows.Controls.ItemContainerGenerator.ItemForItemContainerProperty);
}