Exemplo n.º 1
0
 private void RelocateChildToUwpControl(WindowsXamlHostBase obj)
 {
     if (obj.GetUwpInternalObject() is windows.UI.Xaml.DependencyObject child)
     {
         UwpControl.Children.Add(child);
     }
 }
 internal static void SetUwpControlValue(this WindowsXamlHostBase wrapper, object value, [CallerMemberName] string propName = null)
 {
     Windows.UI.Xaml.UIElement control = wrapper.GetUwpInternalObject() as Windows.UI.Xaml.UIElement;
     if (control != null)
     {
         control.GetType().GetRuntimeProperty(propName).SetValue(control, value);
     }
     else
     {
         Dictionary <string, object> properties = GetDesignerProperties(wrapper);
         properties[propName] = value;
     }
 }
        internal static object GetUwpControlValue(this WindowsXamlHostBase wrapper, object defaultValue = null, [CallerMemberName] string propName = null)
        {
            Windows.UI.Xaml.UIElement control = wrapper.GetUwpInternalObject() as Windows.UI.Xaml.UIElement;
            if (control != null)
            {
                return(control.GetType().GetRuntimeProperty(propName).GetValue(control));
            }
            else
            {
                Dictionary <string, object> properties = GetDesignerProperties(wrapper);
                if (properties.ContainsKey(propName))
                {
                    return(properties[propName]);
                }

                return(defaultValue != null ? defaultValue : GetDefaultValueForProperty(wrapper, propName));
            }
        }
        private static object GetDefaultValueForProperty(WindowsXamlHostBase wrapper, string propName)
        {
            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(wrapper).Find(propName, false);

            if (descriptor == null)
            {
                throw new MissingMethodException("Wrapper class does not contain property " + propName.ToString());
            }

            DefaultValueAttribute attribute = descriptor.Attributes[typeof(DefaultValueAttribute)] as DefaultValueAttribute;

            if (attribute == null)
            {
                throw new ArgumentException("Wrapper class does not define a DefaultValue attribute for property " + propName.ToString());
            }

            return(attribute.Value);
        }
        private static Dictionary <string, object> GetDesignerProperties(WindowsXamlHostBase wrapper)
        {
            PropertyInfo designerProperty = wrapper.GetType().GetProperty(DesignerPropertiesName, BindingFlags.NonPublic | BindingFlags.Instance);

            if (designerProperty == null)
            {
                throw new MissingMethodException("Wrapper class does not contain the required DesignerProperties dictionary");
            }

            Dictionary <string, object> propertiesDictionary = designerProperty.GetValue(wrapper) as Dictionary <string, object>;

            if (propertiesDictionary == null)
            {
                propertiesDictionary = new Dictionary <string, object>();
                designerProperty.SetValue(wrapper, propertiesDictionary);
            }

            return(propertiesDictionary);
        }
 public static void SetWrapper(this Windows.UI.Xaml.UIElement element, WindowsXamlHostBase wrapper)
 {
     element.SetValue(WrapperProperty, wrapper);
 }