本文整理汇总了C#中System.Windows.DependencyObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.GetType方法的具体用法?C# DependencyObject.GetType怎么用?C# DependencyObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ViewToViewModelMappingContainer
/// <summary>
/// Initializes a new instance of the <see cref="ViewToViewModelMappingContainer"/> class.
/// </summary>
/// <param name="dependencyObject">The dependency object.</param>
/// <exception cref="ArgumentNullException">The <paramref name="dependencyObject"/> is <c>null</c>.</exception>
public ViewToViewModelMappingContainer(DependencyObject dependencyObject)
{
Argument.IsNotNull("dependencyObject", dependencyObject);
var properties = dependencyObject.GetType().GetPropertiesEx();
foreach (var property in properties)
{
object[] viewToViewModelAttributes = property.GetCustomAttributesEx(typeof(ViewToViewModelAttribute), false);
if (viewToViewModelAttributes.Length > 0)
{
Log.Debug("Property '{0}' is decorated with the ViewToViewModelAttribute, creating a mapping", property.Name);
var viewToViewModelAttribute = (ViewToViewModelAttribute)viewToViewModelAttributes[0];
string propertyName = property.Name;
string viewModelPropertyName = (string.IsNullOrEmpty(viewToViewModelAttribute.ViewModelPropertyName)) ? propertyName : viewToViewModelAttribute.ViewModelPropertyName;
var mapping = new ViewToViewModelMapping(propertyName, viewModelPropertyName, viewToViewModelAttribute.MappingType);
// Store it (in 2 dictionaries for high-speed access)
_viewToViewModelMappings.Add(property.Name, mapping);
_viewModelToViewMappings.Add(viewModelPropertyName, mapping);
}
}
}
示例2: FindMainGrid
public DependencyObject FindMainGrid(DependencyObject Node)
{
if (Node != null)
{
if (VisualTreeHelper.GetChildrenCount(Node) > 0) //Node has Childrens
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(Node); i++)
{
if (Node.GetType().ToString().Equals("System.Windows.Controls.Grid"))
{
return Node;
}
else
{
return FindMainGrid(VisualTreeHelper.GetChild(Node, i));
}
}
}
else
{
if (Node.GetType().ToString().Equals("System.Windows.Controls.Grid"))
{
return Node;
}
}
}
return null;
}
示例3: GetMetadata
public PropertyMetadata GetMetadata(DependencyObject d)
{
var theType = d.GetType();
if (metadataByType.ContainsKey (d.GetType()))
return metadataByType[d.GetType()];
return null;
}
示例4: OnEventChanged
private static void OnEventChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
if (e.OldValue != null) {
var @event = d.GetType().GetEvent(((RoutedEvent)e.OldValue).Name);
@event.RemoveEventHandler(d, Delegate.CreateDelegate(@event.EventHandlerType, HandlerMethod));
}
if (e.NewValue != null) {
var @event = d.GetType().GetEvent(((RoutedEvent)e.NewValue).Name);
@event.AddEventHandler(d, Delegate.CreateDelegate(@event.EventHandlerType, HandlerMethod));
}
}
示例5: ResolveCommandBehavior
private static IReturnCommandBehavior ResolveCommandBehavior(DependencyObject ctrl)
{
IReturnCommandBehavior behavior;
if (ctrl.GetType() == typeof(TextBox))
behavior = new ReturnCommandBehavior((TextBox)ctrl);
else if (ctrl.GetType() == typeof(PasswordBox))
behavior = new pwReturnCommandBehavior((PasswordBox)ctrl);
else
behavior = null;
return behavior;
}
示例6: BuildupView
private void BuildupView(IComponentContext context, DependencyObject instance)
{
try
{
if (instance == null)
return;
foreach (object c in LogicalTreeHelper.GetChildren(instance))
{
var child = c as DependencyObject;
if (child == null)
continue;
BuildupView(context, child);
}
Type viewInterfaceType = instance.GetType().GetInterface(typeof (IView<>).FullName);
if (viewInterfaceType == null)
return;
PropertyInfo viewModelProperty = viewInterfaceType.GetProperty("ViewModel");
Type viewModelType = viewInterfaceType.GetGenericArguments()[0];
object viewModel = context.Resolve(viewModelType);
viewModelProperty.SetValue(instance, viewModel, null);
viewInterfaceType.GetMethod("ViewInitialized").Invoke(instance, null);
}
catch (Exception e)
{
}
}
示例7: ImgToShowSourcePropertyChange
protected static void ImgToShowSourcePropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d.GetType() == typeof(AGImage))
{
try
{
AGImage ag = d as AGImage;
System.Drawing.Icon ic = (System.Drawing.Icon)LaserControl.Properties.Resources.ResourceManager.GetObject(e.NewValue.ToString());
System.Drawing.Bitmap bmp = ic.ToBitmap();
System.Drawing.Bitmap bmpD = MakeGrayscale3(bmp);
ag.ImgEnabled = BitmapToImageSource(bmp);
ag.ImgDisabled = BitmapToImageSource(bmpD);
ag.Source = ag.IsEnabled ? ag.ImgEnabled : ag.ImgDisabled;
ic.Dispose();
}
catch
{
//Mache nichts
}
}
}
示例8: CoerceMVVMHasError
private static object CoerceMVVMHasError(DependencyObject d,Object baseValue)
{
bool ret=(bool)baseValue ;
if (BindingOperations.IsDataBound(d,MVVMHasErrorProperty))
{
if (GetHasErrorDescriptor(d) == null)
{
DependencyPropertyDescriptor desc=DependencyPropertyDescriptor.FromProperty(Validation.HasErrorProperty, d.GetType());
desc.AddValueChanged(d,OnHasErrorChanged);
SetHasErrorDescriptor(d, desc);
ret = Validation.GetHasError(d);
}
}
else
{
if (GetHasErrorDescriptor(d) != null)
{
DependencyPropertyDescriptor desc= GetHasErrorDescriptor(d);
desc.RemoveValueChanged(d, OnHasErrorChanged);
SetHasErrorDescriptor(d, null);
}
}
return ret;
}
示例9: IsDescendantOf
public bool IsDescendantOf (DependencyObject ancestor)
{
if (!(ancestor is Visual /*|| ancestor is Visual3D*/))
throw new ArgumentException (string.Format ("'{0}' is not a Visual or Visual3D", ancestor.GetType()));
throw new NotImplementedException ();
}
示例10: IsAncestorOf
public bool IsAncestorOf (DependencyObject descendant)
{
if (!(descendant is Visual /*|| descendant is Visual3D*/))
throw new ArgumentException (string.Format ("'{0}' is not a Visual or Visual3D", descendant.GetType()));
throw new NotImplementedException ();
}
示例11: IsEnabledPropertyChanged
private static void IsEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d.GetType() == typeof(PasswordBox))
SetEnabledForPasswordBox((PasswordBox)d, (bool)e.NewValue);
else
SetEnabledForTextBox((TextBox)d, (bool)e.NewValue);
}
示例12: AttachEventHandler
/// <summary>
/// Attaches an event to the first Parent of obj (which must be a
/// FrameworkElement) which declares a public method with the name
/// "handler" and arguments of types "types".
///
/// When that method is found, attacher is invoked with:
/// - sender is "obj"
/// - target is the Parent that declares the method
/// - method is the method of Parent
/// </summary>
/// <param name="obj">the object to which to attach an event</param>
/// <param name="handler">the name of the method to be found in some Parent of obj</param>
/// <param name="attacher">indicates how to attach an event to the target</param>
public static void AttachEventHandler(DependencyObject obj, string methodName, Type[] handlerTypes, EventAttacher attacher)
{
FrameworkElement element = obj as FrameworkElement;
if (element == null)
throw new ArgumentException("Can only attach events to FrameworkElement instances, not to '" + obj.GetType() + "'");
element.Loaded += (sender, e) =>
{
DependencyObject parent = sender as DependencyObject;
MethodInfo info = null;
while (info == null)
{
info = parent.GetType().GetMethod(methodName, handlerTypes);
if (info != null)
{
attacher(sender, parent, info);
return;
}
parent = (parent is FrameworkElement) ? ((FrameworkElement)parent).Parent : null;
if (parent == null)
throw new ArgumentException("Can't find handler '" + methodName + "' (maybe it's not public, or set in a ControlTemplate?)");
}
};
}
示例13: RemoveHandler
public static void RemoveHandler(DependencyObject element, RoutedEvent routedEvent, Delegate handler)
{
if (element == null) { throw new ArgumentNullException("element"); }
var uie = element as UIElement;
if (uie != null)
{
uie.RemoveHandler(routedEvent, handler);
}
else
{
var ce = element as ContentElement;
if (ce != null)
{
ce.RemoveHandler(routedEvent, handler);
}
else
{
var u3d = element as UIElement3D;
if (u3d != null)
u3d.RemoveHandler(routedEvent, handler);
else
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid element {0}.", element.GetType()));
}
}
}
示例14: GetDataGridColumnDependencyProperty
public static DependencyProperty GetDataGridColumnDependencyProperty(DisplayPropertyInfo property, DependencyObject depObject)
{
DependencyProperty dp = null;
if (property.LogicalDependencyProperty == LogicalDependencyProperty.Default)
{
PropertyInfo dpPropertyInfo = depObject.GetType().GetProperty(property.DependencyPropertyName, BindingFlags.Static);
dp = dpPropertyInfo.GetValue(null) as DependencyProperty;
}
else if (property.LogicalDependencyProperty == LogicalDependencyProperty.IsEnabled)
{
dp = DataGridColumn.IsReadOnlyProperty;
}
else if (property.LogicalDependencyProperty == LogicalDependencyProperty.IsVisible)
{
dp = DataGridColumn.VisibilityProperty;
}
else if (property.LogicalDependencyProperty == LogicalDependencyProperty.IsReadOnly)
{
dp = DataGridColumn.IsReadOnlyProperty;
}
if (dp == null)
{
LoggerFactory.GetLogger().Warn("The dependency property of property '{}' cannot be found.", property.PropertyName);
}
return dp;
}
示例15: GetDependencyProperty
public static DependencyProperty GetDependencyProperty(string name, DependencyObject parent, bool caseSensitive = false)
{
const string prop = "Property";
var propertyName = name;
if (!propertyName.ToLower().EndsWith(prop.ToLower()))
{
propertyName += prop;
}
var fieldInfoArray = parent.GetType().GetFields();
foreach (var fieldInfo in fieldInfoArray)
{
if (caseSensitive)
{
if (fieldInfo.Name != propertyName) continue;
var dependencyPropertyField = (DependencyProperty)fieldInfo.GetValue(parent);
return dependencyPropertyField;
}
else
{
if (!string.Equals(fieldInfo.Name, propertyName, StringComparison.CurrentCultureIgnoreCase)) continue;
var dependencyPropertyField = (DependencyProperty)fieldInfo.GetValue(parent);
return dependencyPropertyField;
}
}
throw new Exception("FSR.Reflection.CannotFindDependencyProperty(parent, name, caseSensitive)");
}