Ejemplo n.º 1
0
        public override void SetValue(NativeView view, object value)
        {
            switch (value)
            {
            case null:
                view.SetValue(DependencyProperty, null);
                break;

            case NativeBinding binding:
                binding.Mode = IsTwoWay ? BindingMode.TwoWay : BindingMode.OneWay;
                view.SetBinding(DependencyProperty, binding);
                break;

            default:
                if (!ValueType.IsEnum)
                {
                    value.TryChangeType(ValueType, out value);
                }
                value = Converter == null ? value : Converter.Invoke(value);
                if (value.GetType() == PropertyType)
                {
                    view.SetValue(DependencyProperty, value);
                }
                break;
            }
        }
 /// <summary>
 /// Gets the <see cref="T:System.Windows.Interactivity.BehaviorCollection"/> associated with a specified object.
 /// 
 /// </summary>
 /// <param name="obj">The object from which to retrieve the <see cref="T:System.Windows.Interactivity.BehaviorCollection"/>.</param>
 /// <returns>
 /// A <see cref="T:System.Windows.Interactivity.BehaviorCollection"/> containing the behaviors associated with the specified object.
 /// </returns>
 public static BehaviorCollection GetBehaviors(FrameworkElement obj)
 {
     BehaviorCollection behaviorCollection = (BehaviorCollection)obj.GetValue(Interaction.BehaviorsProperty);
     if (behaviorCollection == null)
     {
         behaviorCollection = new BehaviorCollection();
         obj.SetValue(Interaction.BehaviorsProperty, behaviorCollection);
     }
     return behaviorCollection;
 }
        private IList<IMvxUpdateableBinding> GetOrCreateBindingsList(FrameworkElement attachedObject)
        {
            var existing = attachedObject.GetValue(BindingsListProperty) as IList<IMvxUpdateableBinding>;
            if (existing != null)
                return existing;

            // attach the list
            var newList = new List<IMvxUpdateableBinding>();
            attachedObject.SetValue(BindingsListProperty, newList);

            // create a binding watcher for the list
#if WINDOWS_WPF
            var binding = new System.Windows.Data.Binding();
#endif
#if WINDOWS_COMMON
            var binding = new Windows.UI.Xaml.Data.Binding();
#endif
            bool attached = false;
            Action attachAction = () =>
            {
                if (attached)
                    return;
                BindingOperations.SetBinding(attachedObject, DataContextWatcherProperty, binding);
                attached = true;
            };

            Action detachAction = () =>
            {
                if (!attached)
                    return;
#if WINDOWS_COMMON
                attachedObject.ClearValue(DataContextWatcherProperty);
#else
                BindingOperations.ClearBinding(attachedObject, DataContextWatcherProperty);
#endif
                attached = false;
            };
            attachAction();
            attachedObject.Loaded += (o, args) =>
            {
                attachAction();
            };
            attachedObject.Unloaded += (o, args) =>
            {
                detachAction();
            };

            return newList;
        }
        private static void ReplaceCachedLocalValueHelper(FrameworkElement element, DependencyProperty property, object value)
        {
            if (value == DependencyProperty.UnsetValue)
            {
                element.ClearValue(property);
            }
            else
            {
                //BindingExpression expression = value as BindingExpression;
                //if (expression != null)
                //{
                //    element.SetBinding(property, expression);
                //}
                //else
                //{
                value = ConvertValueToExpectedType(property, value);
                element.SetValue(property, value);

                //}
            }
        }
Ejemplo n.º 5
0
 public static void SetMargin(FrameworkElement target, Thickness value) {
     target.SetValue(MarginProperty, value);
 }
 public static void SetObservedHeight(FrameworkElement frameworkElement, double observedHeight)
 {         
     frameworkElement.SetValue(ObservedHeightProperty, observedHeight);
 }
 public static void SetObserve(FrameworkElement frameworkElement, bool observe)
 {
     frameworkElement.SetValue(ObserveProperty, observe);
 }
 /// <summary>
 /// 将一个 FullWindowPopup 附加到一个 FrameworkElement 上。
 /// </summary>
 /// <param name="obj">被附加的 FrameworkElement。</param>
 /// <param name="value">附加的 FullWindowPopup。</param>
 public static void SetAttachedPopup(FrameworkElement obj, FullWindowPopup value)
 {
     obj.SetValue(AttachedPopupProperty, value);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Sets value describing whether FrameworkElement is acting as View in MVVM.
 /// </summary>
 public static void SetRegisterAsMediaService(FrameworkElement target, bool value)
 {
     target.SetValue(RegisterAsMediaServiceProperty, value);
 }
Ejemplo n.º 10
0
 public static void SetEventArgsAsParameter(FrameworkElement target, bool value) {
     target.SetValue(EventArgsAsParameterProperty, value);
 }
Ejemplo n.º 11
0
 public static void SetCommandParameter(FrameworkElement target, object value) {
     target.SetValue(CommandParameterProperty, value);
 }
Ejemplo n.º 12
0
 public static void SetCommand(FrameworkElement target, ICommand value) {
     target.SetValue(CommandProperty, value);
 }
Ejemplo n.º 13
0
 public static void SetEvent(FrameworkElement target, string value) {
     target.SetValue(EventProperty, value);
 }
Ejemplo n.º 14
0
        private void applyQuadrant(FrameworkElement ctl, string qlocation, int width, int height, bool preSized = false)
        {
            Grid parent;
            int row;
            int col;
            string loc;
            Tuple<int, int> quad;

            parent = FindParentOrCreate(qlocation);

            // Now we will be able to add the new control to the right place.
            loc = qlocation.Substring(qlocation.Length - 1, 1);
            quad = TranslateQLoc(loc);
            row = quad.Item1;
            col = quad.Item2;

            if (width > 0 && !preSized)
                ctl.Width = width * ((IIFControl)ctl).WidthOfAChar;
            else if (!preSized)
                ctl.HorizontalAlignment = HorizontalAlignment.Stretch;

            if (height > 0 && !preSized)
                ctl.Height = height * ((IIFControl)ctl).HeightOfAChar;
            else if (!preSized)
                ctl.VerticalAlignment = VerticalAlignment.Stretch;

            ctl.Name = kCtlName + qlocation; // +"__" + parent.Children.Count;

            if (parent.Children.Count > 0)
            {
                var existing = parent.Children.FirstOrDefault(i => (int)i.GetValue(Grid.ColumnProperty) == col && (int)i.GetValue(Grid.RowProperty) == row);
                // Need to find an existing element that is in our spot
                if (existing is Grid)
                {
                    // tried to place where there is a grid.
                    // Try to place in exact spot in the grid we found
                    applyQuadrant(ctl, qlocation + qlocation.Substring(qlocation.Length - 1, 1), width, height, true);
                    return;
                }
                if (existing != null)
                {
                    var ctlNum = controls.IndexOf((FrameworkElement)existing);

                    splitCell(parent, ctlNum, ctl, "");
                    return;
                }
                // else fall through to insert

                //    moveControlToGrid((FrameworkElement)parent.Children[0]);
                //    var newparent = (Grid)parent.Children[0];

                //    newparent.Children.Add(ctl);
                //    ctl.SetValue(Grid.RowProperty, 1);
                //    ctl.SetValue(Grid.ColumnProperty, 0);
            }
            parent.Children.Add(ctl);
            ctl.SetValue(Grid.RowProperty, row);
            ctl.SetValue(Grid.ColumnProperty, col);
        }
Ejemplo n.º 15
0
 internal void HideItem(FrameworkElement item)
 {
     item.SetValue(FrameworkElement.DataContextProperty, null);
     item.Opacity = 0;
 }
Ejemplo n.º 16
0
 internal void ShowItem(ContainerContentChangingEventArgs args, FrameworkElement item)
 {
     item.SetValue(FrameworkElement.DataContextProperty, DependencyProperty.UnsetValue);
     item.Opacity = 1;
 }
Ejemplo n.º 17
0
 public static void SetContent(FrameworkElement d, object v) {
     d.SetValue(ContentProperty, v);
 }
Ejemplo n.º 18
0
 public static void Change_Row_Column(FrameworkElement d, int row, int column)
 {
     d.SetValue(Grid.RowProperty, row);
     d.SetValue(Grid.ColumnProperty, column);
 }
Ejemplo n.º 19
0
        private void CalculateIndicatorPosition(FrameworkElement indicator, double frequency, double gain)
        {
            if (!this.IsEnabled)
                return;

            indicator.SetValue(Canvas.LeftProperty, (frequency / 100 * this.ActualWidth) - 10);
            indicator.SetValue(Canvas.TopProperty, ((15 - gain) * this.ActualHeight / 30) - 10);
        }
 public static void SetLoadedCommand(FrameworkElement frameworkElement, ICommand value)
 {
     frameworkElement.SetValue(LoadedCommandProperty, value);
 }
 private void AddElementToCanvas(FrameworkElement el)
 {
     if (el == null)
     {
         return;
     }
     el.SetValue(Canvas.LeftProperty, LineWidth);
     el.SetValue(Canvas.TopProperty, Top);
     TextCanvas.Children.Add(el);
     LineWidth += el.Width;
     if (LineHeight < el.Height)
     {
         LineHeight = el.Height;
         SynCanvasHeight();
     }
     FirstInLine = false;
 }
 public static void SetObservedWidth(FrameworkElement frameworkElement, double observedWidth)
 {         
     frameworkElement.SetValue(ObservedWidthProperty, observedWidth);
 }
        /// <summary>
        /// Copy the layout properties from the source element to the target element, clearing them from the source.
        /// </summary>
        /// <param name="source">The source of the layout properties</param>
        /// <param name="target">The destination of the layout properties</param>
        private static void CopyLayoutProperties(FrameworkElement source, FrameworkElement target, bool restoring)
        {
            WrapperCanvas canvas = (restoring ? ((WrapperCanvas)source) : ((WrapperCanvas)target)) as WrapperCanvas;
            if (canvas.LocalValueCache == null)
                canvas.LocalValueCache = new Dictionary<DependencyProperty, object>();

            foreach (DependencyProperty property in LayoutProperties)
            {
                if (!ChildAffectingLayoutProperties.Contains(property))
                {
                    object actualValue = CacheActualValueHelper(source, property);
                    object localValue = CacheLocalValueHelper(source, property);
                    if (actualValue != localValue)
                        return;

                    if (restoring)
                    {
                        ReplaceCachedLocalValueHelper(target, property, canvas.LocalValueCache[property]);
                    }
                    else
                    {
                        object targetValue = target.GetValue(property);
                        canvas.LocalValueCache[property] = localValue;
                        if (IsVisibilityProperty(property))
                        {
                            canvas.DestinationVisibilityCache = (Visibility)source.GetValue(property);
                        }
                        else
                        {
                            target.SetValue(property, source.GetValue(property));
                        }
                        source.SetValue(property, targetValue);
                    }
                }
            }
        }
Ejemplo n.º 24
0
 public static void SetPropertyBinding(FrameworkElement element, SetterValueBindingHelper value)
 {
     if (null == element)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(PropertyBindingProperty, value);
 }
Ejemplo n.º 25
0
 public static void SetHtml(FrameworkElement target, float value) {
     target.SetValue(HtmlProperty, value);
 }