本文整理汇总了C#中Visual.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Visual.GetType方法的具体用法?C# Visual.GetType怎么用?C# Visual.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Visual
的用法示例。
在下文中一共展示了Visual.GetType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDescendantByType
public static Visual GetDescendantByType(Visual element, Type type)
{
if (element == null)
{
return null;
}
if (element.GetType() == type)
{
return element;
}
Visual descendantByType = null;
if (element is FrameworkElement)
{
(element as FrameworkElement).ApplyTemplate();
}
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
Visual child = VisualTreeHelper.GetChild(element, i) as Visual;
descendantByType = GetDescendantByType(child, type);
if (descendantByType != null)
{
return descendantByType;
}
}
return descendantByType;
}
示例2: GetDescendantByType
public static Visual GetDescendantByType(Visual element, Type type)
{
if (element != null)
{
if (element.GetType() != type)
{
Visual foundElement = null;
if (element is FrameworkElement)
{
(element as FrameworkElement).ApplyTemplate();
}
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
Visual visual = VisualTreeHelper.GetChild(element, i) as Visual;
foundElement = GetDescendantByType(visual, type);
if (foundElement != null)
{
break;
}
}
return foundElement;
}
return element;
}
return null;
}
示例3: GetDescendantByType
private static Visual GetDescendantByType(Visual element, Type type)
{
if (element == null) return null;
if (element.GetType() == type || element.GetType().IsSubclassOf(type)) return element;
Visual foundElement = null;
if (element is FrameworkElement)
(element as FrameworkElement).ApplyTemplate();
for (int i = 0;
i < VisualTreeHelper.GetChildrenCount(element); i++)
{
Visual visual = VisualTreeHelper.GetChild(element, i) as Visual;
foundElement = GetDescendantByType(visual, type);
if (foundElement != null)
break;
}
return foundElement;
}
示例4: PrintVisualTree
public void PrintVisualTree(Visual v)
{
if (v == null)
return;
string name = null;
increaseIndent();
if (v is FrameworkElement)
name = ((FrameworkElement)v).Name;
print("Visual Type: " + v.GetType().ToString() + (name != null ? ", Name: " + name : ""));
// recurse through the children
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(v); i++)
{
PrintVisualTree(VisualTreeHelper.GetChild(v, i) as Visual);
}
decreaseIndent();
}
示例5: EventsListener
public EventsListener(Visual visual)
{
EventsListener.current = this;
this.visual = visual;
Type type = visual.GetType();
// Cannot unregister for events once we've registered, so keep the registration simple and only do it once.
for (Type baseType = type; baseType != null; baseType = baseType.BaseType)
{
if (!registeredTypes.ContainsKey(baseType))
{
registeredTypes[baseType] = baseType;
RoutedEvent[] routedEvents = EventManager.GetRoutedEventsForOwner(baseType);
if (routedEvents != null)
{
foreach (RoutedEvent routedEvent in routedEvents)
EventManager.RegisterClassHandler(baseType, routedEvent, new RoutedEventHandler(EventsListener.HandleEvent), true);
}
}
}
}
示例6: DumpVisual
// ------------------------------------------------------------------
//
// Basic UIElement/Visual Dump
//
// ------------------------------------------------------------------
#region Basic UIElement/Visual Dump
// ------------------------------------------------------------------
// Dump content of Visual.
// ------------------------------------------------------------------
internal static void DumpVisual(XmlTextWriter writer, Visual visual, Visual parent)
{
if (visual is UIElement)
{
DumpUIElement(writer, (UIElement)visual, parent, false);
}
else
{
writer.WriteStartElement(visual.GetType().Name);
// Dump visual bounds
Rect bounds = visual.VisualContentBounds;
if(!bounds.IsEmpty)
{
DumpRect(writer, "ContentRect", bounds);
}
// Dump clip geometry
Geometry clip = VisualTreeHelper.GetClip(visual);
if (clip != null)
{
DumpRect(writer, "Clip.Bounds", clip.Bounds);
}
// Dump transform relative to its parent
GeneralTransform g = visual.TransformToAncestor(parent);
Point point = new Point(0, 0);
g.TryTransform(point, out point);
if (point.X != 0 || point.Y != 0)
{
DumpPoint(writer, "Position", point);
}
// Dump visual children
DumpVisualChildren(writer, "Children", visual);
writer.WriteEndElement();
}
}
示例7: FindAllChildren
private void FindAllChildren(Type T, Visual root, List<Visual> elementList)
{
if (root == null)
return;
if (T.Equals(root.GetType()))
{
elementList.Add(root);
return;
}
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
{
Visual child = VisualTreeHelper.GetChild(root, i) as Visual;
FindAllChildren(T, child, elementList);
}
}
示例8: GetDescendantByType
public static Visual GetDescendantByType(Visual element, Type type, string name)
{
if (element == null) return null;
if (element.GetType() == type)
{
FrameworkElement fe = element as FrameworkElement;
if (fe != null)
{
if (fe.Name == name)
{
return fe;
}
}
}
Visual foundElement = null;
if (element is FrameworkElement)
(element as FrameworkElement).ApplyTemplate();
for (int i = 0;
i < VisualTreeHelper.GetChildrenCount(element); i++)
{
Visual visual = VisualTreeHelper.GetChild(element, i) as Visual;
foundElement = GetDescendantByType(visual, type, name);
if (foundElement != null)
break;
}
return foundElement;
}
示例9: GetCanvasZoom
private double GetCanvasZoom(Visual referenceVisual)
{
if (referenceVisual.GetType() == typeof(Canvas))
{
return (referenceVisual as Canvas).LayoutTransform.Value.M11;
}
var parent = VisualTreeHelper.GetParent(referenceVisual) as Visual;
if (parent.GetType() == typeof(Canvas))
{
return (parent as Canvas).LayoutTransform.Value.M11;
}
return 1;
}