本文整理汇总了C#中DependencyObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetType方法的具体用法?C# DependencyObject.GetType怎么用?C# DependencyObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Set
/// <summary>
/// Applies the <see cref="EventSetter"/> to the specified <see cref="DependencyObject"/>
/// </summary>
/// <param name="dependencyObject">The <see cref="DependencyObject"/> to apply the <see cref="EventSetter"/> to</param>
internal override void Set(DependencyObject dependencyObject)
{
EventInfo eventInfo;
eventInfo = dependencyObject.GetType().GetEvent(this.Event.Name);
if(eventInfo == null)
{
throw new MissingMemberException("The specified event '" + this.Event.Name + "' does not exist or could not be found in the type '" + dependencyObject.GetType().FullName + "'");
}
eventInfo.AddEventHandler(dependencyObject, this.Handler);
}
示例2: Attach
/// <inheritdoc/>
protected override void Attach(DependencyObject dobj)
{
var routedEvent = EventManager.FindByStylingName(Ultraviolet, dobj, eventName.Owner, eventName.Name);
if (routedEvent == null)
throw new InvalidOperationException(PresentationStrings.EventOrPropertyDoesNotExist.Format(eventName, dobj.GetType()));
RoutedEvent.RegisterRaisedNotification(dobj, routedEvent, this);
base.Attach(dobj);
}
示例3: Attach
public void Attach(DependencyObject obj) {
if(AssociatedObject == obj)
return;
if(AssociatedObject != null)
throw new InvalidOperationException("Cannot attach this object twice");
Type type = obj.GetType();
if(!this.AssociatedType.IsAssignableFrom(type))
throw new InvalidOperationException(string.Format("This object cannot be attached to a {0} object", type.ToString()));
AssociatedObject = obj;
IsAttached = true;
OnAttached();
}
示例4: Set
/// <summary>
/// Applies the <see cref="Setter"/> to the specified <see cref="DependencyObject"/>
/// </summary>
/// <param name="dependencyObject">The <see cref="DependencyObject"/> to apply the <see cref="Setter"/> to</param>
internal override void Set(DependencyObject dependencyObject)
{
switch (this.Property.Type)
{
case DependencyPropertyType.Property:
if (!dependencyObject.DependencyProperties.ContainsKey(this.Property))
{
throw new MissingMemberException("The specified DependencyProperty does not exist or could not be found in type '" + dependencyObject.GetType().FullName + "'");
}
dependencyObject.SetValue(this.Property, this.Value);
break;
case DependencyPropertyType.AttachedProperty:
dependencyObject.DependencyProperties.Add(this.Property, this.Value);
break;
}
}
示例5: FindAncestorOfType
public static bool FindAncestorOfType(DependencyObject current, out DependencyObject ancestor, Type ancestorType)
{
ancestor = null;
while (current != null)
{
if (ancestorType == null ||
ancestorType.IsAssignableFrom(current.GetType()))
{
ancestor = current;
return true;
}
DependencyObject c = current;
if (!FindParent_VT(c, out current) && !FindParent_LT(c, out current))
return false;
}
return false;
}
示例6: InitializeObject
/// <summary>
/// Initializes the specified object's dependency properties.
/// </summary>
/// <param name="dobj">The object to initialize.</param>
public static void InitializeObject(DependencyObject dobj)
{
Contract.Require(dobj, "dobj");
var type = dobj.GetType();
while (type != null && typeof(DependencyObject).IsAssignableFrom(type))
{
var domain = GetPropertyDomain(type);
foreach (var kvp in domain)
{
dobj.InitializeDependencyProperty(kvp.Value);
}
type = type.BaseType;
}
}
示例7: Attach
/// <inheritdoc/>
protected override void Attach(DependencyObject dobj)
{
if (IsAttachedTo(dobj))
return;
foreach (var condition in conditions)
{
var dprop = DependencyProperty.FindByStylingName(Ultraviolet, dobj, condition.PropertyName.Owner, condition.PropertyName.Name);
if (dprop == null)
throw new InvalidOperationException(PresentationStrings.EventOrPropertyDoesNotExist.Format(condition.PropertyName, dobj.GetType()));
DependencyProperty.RegisterChangeNotification(dobj, dprop, this);
}
base.Attach(dobj);
Evaluate(dobj);
}
示例8: FindAncestor
protected bool FindAncestor(DependencyObject current, out DependencyObject ancestor, FindParentMode mode, int ancestorLevel, Type ancestorType)
{
ancestor = null;
if (!FindParent(current, out current, mode)) // Start from the first ancestor
return false;
int ct = ancestorLevel;
while (current != null)
{
if (ancestorType == null ||
ancestorType.IsAssignableFrom(current.GetType()))
ct -= 1;
if (ct == 0)
{
ancestor = current;
return true;
}
if (!FindParent(current, out current, mode))
return false;
}
return false;
}
示例9: GetDefaultBindingMode
private static BindingMode GetDefaultBindingMode(DependencyObject dependencyObject, DependencyProperty dependencyProperty)
{
FrameworkPropertyMetadata frameworkPropertyMetadata = dependencyProperty.GetMetadata(dependencyObject.GetType()) as FrameworkPropertyMetadata;
return frameworkPropertyMetadata != null && frameworkPropertyMetadata.BindsTwoWayByDefault ? BindingMode.TwoWay : BindingMode.OneWay;
}
示例10: VerifyComplexPathSupport
/// <summary>
/// Check to see if the given object and property combination will be
/// able to resolve complex paths.
/// </summary>
private void VerifyComplexPathSupport( DependencyObject targetObject )
{
if( FrameworkElement.DType.IsInstanceOfType(targetObject) )
{
// FrameworkElement and derived types are supported.
return;
}
if( FrameworkContentElement.DType.IsInstanceOfType(targetObject) )
{
// FrameworkContentElement and derived types are supported.
return;
}
// ... and anything else that knows to call into Storyboard.GetComplexPathValue.
// Otherwise - throw.
throw new InvalidOperationException(SR.Get(SRID.Storyboard_ComplexPathNotSupported, targetObject.GetType().ToString()));
}
示例11: GetCurrentPropertyValue
//.........这里部分代码省略.........
return storage._snapshotValue;
}
object currentPropertyValue = baseValue;
if (currentPropertyValue == DependencyProperty.UnsetValue)
{
currentPropertyValue = metadata.GetDefaultValue(d, dp);
}
Debug.Assert(currentPropertyValue != DependencyProperty.UnsetValue);
//
// Process property trigger animations.
//
if (storage._propertyTriggerLayers != null)
{
int count = storage._propertyTriggerLayers.Count;
Debug.Assert(count > 0);
IList<AnimationLayer> layers = storage._propertyTriggerLayers.Values;
for (int i = 0; i < count; i++)
{
currentPropertyValue = layers[i].GetCurrentValue(currentPropertyValue);
}
}
//
// Process local animations
//
if (storage._animationClocks != null)
{
FrugalObjectList<AnimationClock> clocks = storage._animationClocks;
int clocksCount = clocks.Count;
bool hasActiveOrFillingClock = false;
// default destination value will be the current property value
// calculated by the previous layer.
object defaultDestinationValue = currentPropertyValue;
object currentLayerValue = currentPropertyValue;
// if we have a snapshot value, then that will be the new
// initial current property value.
if (storage._snapshotValue != DependencyProperty.UnsetValue)
{
currentLayerValue = storage._snapshotValue;
}
Debug.Assert(clocksCount > 0);
Debug.Assert(defaultDestinationValue != DependencyProperty.UnsetValue);
for (int i = 0; i < clocksCount; i++)
{
if (clocks[i].CurrentState != ClockState.Stopped)
{
hasActiveOrFillingClock = true;
currentLayerValue = clocks[i].GetCurrentValue(currentLayerValue, defaultDestinationValue);
// An animation may not return DependencyProperty.UnsetValue as its
// current value.
if (currentLayerValue == DependencyProperty.UnsetValue)
{
throw new InvalidOperationException(SR.Get(
SRID.Animation_ReturnedUnsetValueInstance,
clocks[i].Timeline.GetType().FullName,
dp.Name,
d.GetType().FullName));
}
}
}
// The currentLayerValue only applies when there is at least one
// active or filling clock.
if (hasActiveOrFillingClock)
{
currentPropertyValue = currentLayerValue;
}
}
// We have a calculated currentPropertyValue, so return it if the type matches.
if (DependencyProperty.IsValidType(currentPropertyValue, dp.PropertyType))
{
return currentPropertyValue;
}
else
{
// If the animation(s) applied to the property have calculated an
// invalid value for the property then raise an exception.
throw new InvalidOperationException(
SR.Get(
SRID.Animation_CalculatedValueIsInvalidForProperty,
dp.Name,
(currentPropertyValue == null ? "null" : currentPropertyValue.ToString())));
}
}
示例12: CreateRegion
/// <summary>
/// Method that will create the region, by calling the right <see cref="IRegionAdapter"/>.
/// </summary>
/// <param name="targetElement">The target element that will host the <see cref="IRegion"/>.</param>
/// <param name="regionName">Name of the region.</param>
/// <returns>The created <see cref="IRegion"/></returns>
protected virtual IRegion CreateRegion(DependencyObject targetElement, string regionName)
{
if (targetElement == null) throw new ArgumentNullException("targetElement");
try
{
// Build the region
IRegionAdapter regionAdapter = this.regionAdapterMappings.GetMapping(targetElement.GetType());
IRegion region = regionAdapter.Initialize(targetElement, regionName);
return region;
}
catch (Exception ex)
{
throw new RegionCreationException(string.Format(CultureInfo.CurrentCulture, ResourceHelper.RegionCreationException, regionName, ex), ex);
}
}
示例13: TraceDependencyObject
/// <summary>
/// Traces the dependency object.
/// </summary>
/// <param name="dob">
/// The dependency object.
/// </param>
/// <param name="i">
/// The object index.
/// </param>
private static void TraceDependencyObject(DependencyObject dob, int i)
{
var frameworkElement = dob as FrameworkElement;
if (frameworkElement == null)
{
Debug.WriteLine(
"path[{0}] is Dependency Object: {1}",
i,
dob.GetType());
}
else
{
var c = frameworkElement as Control;
var cc = frameworkElement as ContentControl;
var panel = frameworkElement as Panel;
var parentGrid = frameworkElement.Parent as Grid;
var image = frameworkElement as Image;
var scrollViewer = frameworkElement as ScrollViewer;
Debug.WriteLine(
"path[{0}] is Control: {1}({2}):",
i,
frameworkElement.GetType(),
frameworkElement.Name ?? "<unnamed>");
// Actual layout information
Debug.WriteLine(
"\tActualWidth={0}\r\n\tActualHeight={1}",
frameworkElement.ActualWidth,
frameworkElement.ActualHeight);
#if NETFX_CORE
var rootVisual = Window.Current.Content;
var pos =
frameworkElement
.TransformToVisual(rootVisual)
.TransformPoint(new Point());
var pos2 =
frameworkElement
.TransformToVisual(rootVisual)
.TransformPoint(
new Point(
frameworkElement.ActualWidth,
frameworkElement.ActualHeight));
#endif
#if WINDOWS_PHONE
var rootVisual = Application.Current.RootVisual;
var pos =
frameworkElement
.TransformToVisual(rootVisual)
.Transform(new Point());
var pos2 =
frameworkElement
.TransformToVisual(rootVisual)
.Transform(
new Point(
frameworkElement.ActualWidth,
frameworkElement.ActualHeight));
#endif
Debug.WriteLine(
"\tPosition – X={0}, Y={1}, Right={2}, Bottom={3}",
pos.X,
pos.Y,
pos2.X,
pos2.Y);
if (frameworkElement.Opacity < 1.0)
{
Debug.WriteLine("\tOpacity={0}", frameworkElement.Opacity);
}
if (frameworkElement.Visibility != Visibility.Visible)
{
Debug.WriteLine("\tVisibility={0}", frameworkElement.Visibility);
}
if (frameworkElement.Clip != null)
{
#if NETFX_CORE
Debug.WriteLine("\tClip={0}", frameworkElement.Clip.Rect);
#endif
#if WINDOWS_PHONE
Debug.WriteLine("\tClip={0}", frameworkElement.Clip.Bounds);
#endif
}
var hashCode = frameworkElement.DataContext != null
? "HashCode: " + frameworkElement.DataContext.GetHashCode()
: string.Empty;
//.........这里部分代码省略.........
示例14: TryGetPropertyPathTarget
private static bool TryGetPropertyPathTarget(DependencyObject root, PropertyPath propertyPath, out DependencyObject target, out DependencyProperty targetProperty)
{
object baseValue;
target = propertyPath.Elements.Count() > 1 && propertyPath.GetBasePropertyPath().TryGetValue(root, out baseValue) ? baseValue as DependencyObject : root;
if (target != null && !propertyPath.IsEmpty)
{
return propertyPath.Elements.Last().TryGetDependencyProperty(target.GetType(), out targetProperty);
}
target = null;
targetProperty = null;
return false;
}
示例15: 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();
}