本文整理汇总了C#中DependencyObject.GetLocalValueEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetLocalValueEnumerator方法的具体用法?C# DependencyObject.GetLocalValueEnumerator怎么用?C# DependencyObject.GetLocalValueEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetLocalValueEnumerator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArrayToLocalValueEnumerator
// Converts array of PropertyRecords into a LocalValueEnumerator.
// The array is safe to cache, LocalValueEnumerators are not.
internal static LocalValueEnumerator ArrayToLocalValueEnumerator(PropertyRecord[] records)
{
DependencyObject obj;
int i;
obj = new DependencyObject();
for (i = 0; i < records.Length; i++)
{
obj.SetValue(records[i].Property, records[i].Value);
}
return obj.GetLocalValueEnumerator();
}
示例2: WriteComplexProperties
/// <summary>
/// Writes complex properties in form of child elements with compound names
/// </summary>
/// <SecurityNote>
/// To mask the security exception from XamlWriter.Save in partial trust case,
/// this function checks if the current call stack has unmanaged code permission.
/// </SecurityNote>
private static void WriteComplexProperties(XmlWriter xmlWriter, DependencyObject complexProperties, Type elementType)
{
if (!SecurityHelper.CheckUnmanagedCodePermission())
{
// In partial trust, we cannot serialize any complex properties because
// XamlWriter.Save demands UnmanagedCodePermission.
//
// If we're in PT, drop the properties.
//
// If you're here debugging a lost complex property, consider adding
// code to DPTypeDescriptorContext to convert the complex property
// into a non-complex property, or consider modifying XamlWriter.Save.
return;
}
LocalValueEnumerator properties = complexProperties.GetLocalValueEnumerator();
properties.Reset();
while (properties.MoveNext())
{
LocalValueEntry propertyEntry = properties.Current;
// Build an appropriate name for the complex property
string complexPropertyName = GetPropertyNameForElement(propertyEntry.Property, elementType, /*forceComplexName:*/true);
// Write the start element for the complex property.
xmlWriter.WriteStartElement(complexPropertyName);
// Serialize the complex property value from SaveAsXml().
string complexPropertyXml = System.Windows.Markup.XamlWriter.Save(propertyEntry.Value);
// Write the serialized complext property value as Xml.
xmlWriter.WriteRaw(complexPropertyXml);
// Close the element for the complex property
xmlWriter.WriteEndElement();
}
}
示例3: GetPropertyRecordArray
// Gets an array of PropertyRecords from a DependencyObject's LocalValueEnumerator.
// The array is safe to cache, LocalValueEnumerators are not.
internal static PropertyRecord[] GetPropertyRecordArray(DependencyObject d)
{
LocalValueEnumerator valuesEnumerator = d.GetLocalValueEnumerator();
PropertyRecord[] records = new PropertyRecord[valuesEnumerator.Count];
int count = 0;
valuesEnumerator.Reset();
while (valuesEnumerator.MoveNext())
{
DependencyProperty dp = valuesEnumerator.Current.Property;
if (!dp.ReadOnly)
{
// LocalValueEntry.Value can be an Expression, which we can't duplicate when we
// undo, so we copy over the current value from DependencyObject.GetValue instead.
records[count].Property = dp;
records[count].Value = d.GetValue(dp);
count++;
}
}
PropertyRecord[] trimmedResult;
if(valuesEnumerator.Count != count)
{
trimmedResult = new PropertyRecord[count];
for(int i=0; i<count; i++)
{
trimmedResult[i] = records[i];
}
}
else
{
trimmedResult = records;
}
return trimmedResult;
}