本文整理匯總了C#中Windows.UI.Xaml.DependencyObject.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# DependencyObject.GetType方法的具體用法?C# DependencyObject.GetType怎麽用?C# DependencyObject.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.UI.Xaml.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: EnsureDataBindingUpToDateOnMembers
public static void EnsureDataBindingUpToDateOnMembers(DependencyObject dpObject)
{
IList<DependencyProperty> list = null;
if (!DependenciesPropertyCache.TryGetValue(dpObject.GetType(), out list))
{
list = new List<DependencyProperty>();
for (Type type = dpObject.GetType(); type != null; type = type.GetTypeInfo().BaseType)
{
foreach (FieldInfo info in type.GetRuntimeFields())
{
if (info.IsPublic && (info.FieldType == typeof(DependencyProperty)))
{
DependencyProperty item = info.GetValue(null) as DependencyProperty;
if (item != null)
{
list.Add(item);
}
}
}
}
DependenciesPropertyCache[dpObject.GetType()] = list;
}
if (list != null)
{
foreach (DependencyProperty property2 in list)
{
EnsureBindingUpToDate(dpObject, property2);
}
}
}
示例2: Attach
/// <summary>
/// Attaches to the specified object.
/// </summary>
/// <param name="dependencyObject">
/// The object to attach to.
/// </param>
/// <exception cref="InvalidOperationException">
/// The Behavior is already hosted on a different element.
/// </exception>
/// <exception cref="InvalidOperationException">
/// dependencyObject does not satisfy the Behavior type constraint.
/// </exception>
public void Attach(DependencyObject dependencyObject)
{
if (this.AssociatedObject != null)
{
throw new InvalidOperationException("The Behavior is already hosted on a different element.");
}
_associatedObject = dependencyObject;
if (dependencyObject != null)
{
if (!this.AssociatedType.GetTypeInfo().IsAssignableFrom(dependencyObject.GetType().GetTypeInfo()))
{
throw new InvalidOperationException("dependencyObject does not satisfy the Behavior type constraint.");
}
var frameworkElement = this.AssociatedObject as FrameworkElement;
if (frameworkElement != null)
{
frameworkElement.Loaded += AssociatedFrameworkElementLoaded;
frameworkElement.Unloaded += AssociatedFrameworkElementUnloaded;
}
OnAttached();
}
}
示例3: GetBehavior
private static DelayedRegionCreationBehavior GetBehavior(DependencyObject control, MockRegionManagerAccessor accessor, MockRegionAdapter adapter)
{
var mappings = new RegionAdapterMappings();
mappings.RegisterMapping(control.GetType(), adapter);
var behavior = new DelayedRegionCreationBehavior(mappings) { RegionManagerAccessor = accessor, TargetElement = control };
return behavior;
}
示例4: AssertAttachArgument
private void AssertAttachArgument(DependencyObject associatedObject)
{
if (this.AssociatedObject != null)
{
throw new InvalidOperationException("multiple time associate.");
}
if (associatedObject == null)
{
throw new ArgumentNullException("associatedObject");
}
if (!this.AssociatedType.GetTypeInfo().IsAssignableFrom(associatedObject.GetType().GetTypeInfo()))
{
throw new ArgumentException(string.Format("{0} can't assign {1}",
associatedObject.GetType().FullName,
this.AssociatedType.FullName));
}
}
示例5: Attach
public void Attach(DependencyObject obj)
{
AssociatedObject = obj;
var evt = AssociatedObject.GetType().GetRuntimeEvent(Event);
if (evt != null)
{
Observable.FromEventPattern<RoutedEventArgs>(AssociatedObject, Event)
.Subscribe(se => FireCommand(se.EventArgs));
}
}
示例6: SelectStyleCore
protected override Style SelectStyleCore(object item, DependencyObject container)
{
SolidColorBrush highlight;
if (_index % 2 == 0)
highlight = new SolidColorBrush(Colors.White);
else
highlight = new SolidColorBrush(Colors.CornflowerBlue);
_index++;
Style style = new Style(container.GetType());
style.Setters.Add(new Setter(Control.BackgroundProperty, highlight));
return style;
}
示例7: DumpVisualTree
private void DumpVisualTree(DependencyObject parent, ref List<DependencyObject> objects)
{
string typeName = parent.GetType().Name;
string name = (string)(parent.GetValue(FrameworkElement.NameProperty) ?? "");
if (parent == null) return;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(parent, i);
objects.Add(child);
DumpVisualTree(child, ref objects);
}
}
示例8: Attach
public void Attach(DependencyObject dependencyObject)
{
Type t = dependencyObject.GetType();
string name = this.EventName;
var eventinfo = t.GetRuntimeEvent(name);
if (string.IsNullOrEmpty(name))
throw new ArgumentException("請指定事件名稱");
if (eventinfo == null)
throw new ArgumentException("指定需要動態添加的事件不存在");
var executemethodinfo = this.GetType().GetTypeInfo().GetDeclaredMethod("Invok").CreateDelegate(eventinfo.EventHandlerType, this);
WindowsRuntimeMarshal.AddEventHandler(
del => (EventRegistrationToken)eventinfo.AddMethod.Invoke(dependencyObject, new object[] { del }),
token => eventinfo.RemoveMethod.Invoke(dependencyObject, new object[] { token }), executemethodinfo);
this.associatedObject = dependencyObject;
}
示例9: OnRoutedEventChanged
private static void OnRoutedEventChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
string routedEvent = (string)e.NewValue;
if (!string.IsNullOrEmpty(routedEvent))
{
EventHooker eventHooker = new EventHooker();
eventHooker.ControlCommandObject = d;
EventInfo eventInfo = GetEventInfo(d.GetType(), routedEvent);
if (eventInfo != null)
{
eventInfo.AddEventHandler(d, eventHooker.GetEventHandler(eventInfo));
//System.Runtime.InteropServices.WindowsRuntime.EventRegistrationTokenTable<RoutedEventArgs>
//Info: http://www.microsoft.com/en-us/download/details.aspx?id=29058
//var eventpattern = System.Reactive.Linq.Observable.FromEventPattern<RoutedEventArgs>(d, routedEvent);
}
}
}
示例10: Attach
public void Attach(DependencyObject dependencyObject)
{
if (this.AssociatedObject != dependencyObject)
{
if (this.AssociatedObject != null)
{
// TODO: message
throw new InvalidOperationException();
}
if (dependencyObject == null) throw new ArgumentNullException(nameof(dependencyObject));
if (!this.AssociatedType.GetTypeInfo().IsAssignableFrom(dependencyObject.GetType().GetTypeInfo()))
{
// TODO: message
throw new InvalidOperationException();
}
this._associatedObject = dependencyObject;
this.RaiseAssociatedObjectChanged();
this.OnAttached();
}
}
示例11: TraceDependencyObject
/// <summary>
/// Traces the dependency object.
/// </summary>
/// <param name="dob">
/// The dependancy 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);
var pos =
frameworkElement
.TransformToVisual(Window.Current.Content)
.TransformPoint(new Point());
var pos2 =
frameworkElement
.TransformToVisual(Window.Current.Content)
.TransformPoint(
new Point(
frameworkElement.ActualWidth,
frameworkElement.ActualHeight));
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);
}
// DataContext often turns out to be a surprise
Debug.WriteLine(
"\tDataContext: {0} {1}",
frameworkElement.DataContext,
frameworkElement.DataContext != null
? "HashCode: " + frameworkElement.DataContext.GetHashCode()
: "");
// List common layout properties
if (!double.IsNaN(frameworkElement.Width) ||
!double.IsNaN(frameworkElement.Height))
{
Debug.WriteLine(
"\tWidth={0}\r\n\tHeight={1}",
frameworkElement.Width,
frameworkElement.Height);
}
if (scrollViewer != null)
{
Debug.WriteLine(
"\tScrollViewer.HorizontalOffset={0}\r\n\tScrollViewer.ViewportWidth={1}\r\n\tScrollViewer.ExtentWidth={2}\r\n\tScrollViewer.VerticalOffset={3}\r\n\tScrollViewer.ViewportHeight={4}\r\n\tScrollViewer.ExtentHeight={5}",
scrollViewer.HorizontalOffset,
scrollViewer.ViewportWidth,
scrollViewer.ExtentWidth,
scrollViewer.VerticalOffset,
scrollViewer.ViewportHeight,
scrollViewer.ExtentHeight
);
}
if (frameworkElement.MinWidth > 0 ||
frameworkElement.MinHeight > 0 ||
!double.IsInfinity(frameworkElement.MaxWidth) ||
!double.IsInfinity(frameworkElement.MaxHeight))
{
//.........這裏部分代碼省略.........
示例12: Attach
/// <summary>
/// Attaches an instance of a DependencyObject to this instance
/// </summary>
/// <param name="dependencyObject">The instance to attach</param>
public void Attach(DependencyObject dependencyObject)
{
AssociatedObject = dependencyObject;
if (!string.IsNullOrEmpty(EventName))
{
EventWrapper eventHooker = new EventWrapper(this);
eventHooker.AssociatedObject = dependencyObject;
EventInfo eventInfo = GetEventInfo(dependencyObject.GetType(), EventName);
if (eventInfo != null)
{
Delegate handler = eventHooker.GetEventHandler(eventInfo);
WindowsRuntimeMarshal.AddEventHandler<Delegate>(
dlg => (EventRegistrationToken)eventInfo.AddMethod.Invoke(dependencyObject, new object[] { dlg }),
etr => eventInfo.RemoveMethod.Invoke(dependencyObject, new object[] { etr }), handler);
}
}
}
示例13: UpdateProperties
private static void UpdateProperties(DependencyObject attachedObject, string properties, string uid)
{
#if DEBUG
if (DesignMode.DesignModeEnabled)
{
return;
}
#endif
IEnumerable<string> props = properties.Split(',');
Type attachedType = attachedObject.GetType();
bool hasProperties = props.Any();
foreach (PropertyInfo propInfo in props.Select(attachedType.GetRuntimeProperty).Where(propInfo => propInfo != null))
{
string value = hasProperties ? ResourceService.GetString(uid, properties) : ResourceService.GetString(uid);
propInfo.SetValue(attachedObject, value);
}
}
示例14: 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);
}
}
示例15: CmdChanged
private static void CmdChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
var t = d.GetType();
var evtName = GetEvent((FrameworkElement)d);
var evt = t.GetEvent(evtName);
if (evt != null) {
//Adding or removing event handlers dynamically is not supported on WinRT events.
//evt.AddEventHandler(d, new TypedEventHandler<DependencyObject, object>(EventDelegate));
// http://stackoverflow.com/questions/16647198/how-to-dynamically-bind-event-to-command-in-winrt-without-reactive-framework
var addMethod = evt.AddMethod;
var removeMethod = evt.RemoveMethod;
var addParameters = addMethod.GetParameters();
var delegateType = addParameters[0].ParameterType;
Action<object, object> handler = (sender, args) => {
////sender maybe not attached objected.
//FireCommand(sender, args as RoutedEventArgs);
FireCommand(d, args);
};
var invoke = typeof(Action<object, object>).GetRuntimeMethod("Invoke", new[] { typeof(object), typeof(object) });
var @delegate = invoke.CreateDelegate(delegateType, handler);
try {
Func<object, EventRegistrationToken> add = a => (EventRegistrationToken)addMethod.Invoke(d, new object[] { @delegate });
Action<EventRegistrationToken> remove = tt => removeMethod.Invoke(d, new object[] { tt });
WindowsRuntimeMarshal.AddEventHandler(add, remove, handler);
} catch {
}
}
}