Пример #1
0
        /// <summary>
        /// Binds this wrapper object's exposed WPF DependencyProperty with the wrapped UWP object's DependencyProperty
        /// for what effectively works as a regular one- or two-way binding.
        /// </summary>
        /// <param name="propertyName">the registered name of the dependency property</param>
        /// <param name="wpfProperty">the DependencyProperty of the wrapper</param>
        /// <param name="uwpProperty">the related DependencyProperty of the UWP control</param>
        /// <param name="converter">a converter, if one's needed</param>
        /// <param name="direction">indicates that the binding should be one or two directional.  If one way, the Uwp control is only updated from the wrapper.</param>
        public void Bind(string propertyName, DependencyProperty wpfProperty, Windows.UI.Xaml.DependencyProperty uwpProperty, object converter = null, BindingDirection direction = BindingDirection.TwoWay)
        {
            if (direction == BindingDirection.TwoWay)
            {
                var binder = new Windows.UI.Xaml.Data.Binding()
                {
                    Source    = this,
                    Path      = new Windows.UI.Xaml.PropertyPath(propertyName),
                    Converter = (Windows.UI.Xaml.Data.IValueConverter)converter
                };
                Windows.UI.Xaml.Data.BindingOperations.SetBinding(ChildInternal, uwpProperty, binder);
            }

            var rebinder = new Binding()
            {
                Source    = ChildInternal,
                Path      = new PropertyPath(propertyName),
                Converter = (IValueConverter)converter
            };

            BindingOperations.SetBinding(this, wpfProperty, rebinder);
        }
Пример #2
0
        static public string GetDependencyPropertyName(this Windows.UI.Xaml.DependencyObject obj, Windows.UI.Xaml.DependencyProperty depprop)
        {
            foreach (var field in obj.GetType().GetFields(BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public))
            {
                if (field.FieldType == typeof(Windows.UI.Xaml.DependencyProperty) && field.GetValue(null) == depprop)
                {
                    return(field.Name);
                }
            }

            foreach (var prop in obj.GetType().GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public))
            {
                if (prop.PropertyType == typeof(Windows.UI.Xaml.DependencyProperty) && prop.GetValue(null) == depprop)
                {
                    return(prop.Name);
                }
            }

            return(null);
        }