Getting the attached property “Canvas.Left”

前端 未结 1 1165
暖寄归人
暖寄归人 2021-01-27 01:34

I have the following code:

this.Object.GetType().GetProperty(this.PropertyName).GetValue(this.Object, null);

PropertyName is a string, containi

相关标签:
1条回答
  • 2021-01-27 02:16

    I think this is because Canvas.Left is attached property and to retrieve them try this:

    private DependencyProperty GetAttachedProperty(DependencyObject obj, string propertyName, Type ownerType)
    {
    
        foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(obj,
            new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) }))
        {
            DependencyPropertyDescriptor dpd =
                DependencyPropertyDescriptor.FromProperty(pd);
    
            if (dpd != null && dpd.IsAttached)
            {
                if (string.Compare(dpd.DependencyProperty.Name, propertyName, StringComparison.CurrentCultureIgnoreCase) == 0 && dpd.DependencyProperty.OwnerType == ownerType)
                {
                    return dpd.DependencyProperty;
                }
            }
        }
    
        return null;
    }
    

    Source

    0 讨论(0)
提交回复
热议问题