Пример #1
0
 public ParentValue UpdateAttachedParent(object source, object attachedParent, object[] args)
 {
     if (_parentMember != null && _parentMember.CanWrite &&
         (attachedParent == null || _parentMember.Type.IsInstanceOfType(attachedParent)))
     {
         _parentMember.SetValue(source, args);
     }
     return(new ParentValue(attachedParent, _parentMember));
 }
Пример #2
0
        protected override void Refresh()
        {
            string selectedTag = _tabHost.CurrentTabTag;
            var    oldValues   = new Dictionary <string, TabInfo>(_tabToContent);

            _tabHost.CurrentTab = 0;
            _tabHost.ClearAllTabs();
            _tabToContent.Clear();

            int count = ItemsSource.Count();

            for (int i = 0; i < count; i++)
            {
                var tabInfo = TryRecreateTabInfo(i, oldValues);
                _tabHost.AddTab(tabInfo.TabSpec);
            }
            foreach (var oldValue in oldValues)
            {
                RemoveTab(oldValue.Value);
            }


            if (count == 0)
            {
                OnEmptyTab();
            }
            else
            {
                if (selectedTag == null)
                {
                    _tabHost.CurrentTab = 0;
                    if (_selectedItemMember != null)
                    {
                        _selectedItemMember.SetValue(_tabHost, new[] { GetItem(0) });
                    }
                }
                else
                {
                    _tabHost.SetCurrentTabByTag(selectedTag);
                }
            }
        }
 private void OnEmptyTab()
 {
     if (_selectedItemMember != null)
     {
         _selectedItemMember.SetValue(TabHost, BindingExtensions.NullValue);
     }
     if (TabHost.TabContentView != null)
     {
         TabHost.TabContentView.RemoveAllViews();
     }
 }
Пример #4
0
 /// <summary>
 ///     Attempts to track the value change.
 /// </summary>
 public IDisposable TryObserve(object source, IEventListener listener)
 {
     if (_isDataContext)
     {
         return(WeakEventManager.GetBindingContextListener(source).AddWithUnsubscriber(listener));
     }
     if (_memberEvent == null)
     {
         return(null);
     }
     return(_memberEvent.SetValue(source, new object[] { listener }) as IDisposable);
 }
        private static void PopupMenuEventChanged(View view, AttachedMemberChangedEventArgs <string> args)
        {
            if (string.IsNullOrEmpty(args.NewValue))
            {
                return;
            }
            IBindingMemberInfo member = BindingServiceProvider
                                        .MemberProvider
                                        .GetBindingMember(view.GetType(), args.NewValue, false, true);
            var presenter    = ServiceProvider.AttachedValueProvider.GetOrAdd(view, "!@popup", (view1, o) => new PopupMenuPresenter(view1), null);
            var unsubscriber = member.SetValue(view, new object[] { presenter }) as IDisposable;

            presenter.Update(unsubscriber);
        }
Пример #6
0
            public ParentValue UpdateAttachedParent(object source, object[] args)
            {
                var attachedParent = args[0];

                if (_isExplicit)
                {
                    if ((_parentMember != null) && _parentMember.CanWrite &&
                        ((attachedParent == null) || _parentMember.Type.IsInstanceOfType(attachedParent)))
                    {
                        _parentMember.SetValue(source, args);
                    }
                }
                return(new ParentValue(attachedParent, _parentMember, _isExplicit));
            }
        /// <summary>
        ///     Attempts to track the value change.
        /// </summary>
        public IDisposable TryObserve(object source, IEventListener listener)
        {
#if WINDOWS_PHONE
            var frameworkElement = source as FrameworkElement;
            if (frameworkElement != null && _path == AttachedMemberConstants.DataContext)
            {
                return(DataContextChangedHelper.Listen(frameworkElement, listener));
            }
#endif
            if (_changePropertyMember == null)
#if NETFX_CORE || WINDOWSCOMMON || WINDOWS_PHONE
            { return(new DependencyPropertyListener(source, _path, listener)); }
#else
            { return(new DependencyPropertyListener(source, _dependencyProperty, listener)); }
#endif
            return(_changePropertyMember.SetValue(source, new object[] { listener }) as IDisposable);
        }
Пример #8
0
        private static void SetAttributeValue(View view, Context context, IAttributeSet attrs, int[] groupId,
                                              int requiredAttributeId, string attachedMemberName, IDataContext dataContext, DataConstant <int> constant)
        {
            int?value = ReadAttributeValueId(context, attrs, groupId, requiredAttributeId);

            if (!value.HasValue)
            {
                return;
            }
            dataContext.Add(constant, value.Value);
            IBindingMemberInfo member = BindingServiceProvider
                                        .MemberProvider
                                        .GetBindingMember(view.GetType(), attachedMemberName, false, false);

            if (member != null)
            {
                member.SetValue(view, new object[] { value });
            }
        }
 private void OnEmptyTab()
 {
     _selectedItemMember?.SetValue(TabHost, BindingExtensions.NullValue);
     TabHost.TabContentView?.RemoveAllViews();
 }
Пример #10
0
        /// <summary>
        ///     Sets the source value.
        /// </summary>
        /// <param name="targetAccessor">The specified accessor to get value.</param>
        /// <param name="context">The specified operation context.</param>
        /// <param name="throwOnError">
        ///     true to throw an exception if the value cannot be set.
        /// </param>
        protected override bool SetValueInternal(IBindingSourceAccessor targetAccessor, IDataContext context,
                                                 bool throwOnError)
        {
            IBindingPathMembers members = _bindingSource.GetPathMembers(throwOnError);

            if (!members.AllMembersAvailable)
            {
                return(false);
            }

            object             penultimateValue = members.PenultimateValue;
            IBindingMemberInfo lastMember       = members.LastMember;

            object oldValue;
            object newValue = targetAccessor.GetValue(lastMember, context, throwOnError);

            if (lastMember.CanRead)
            {
                oldValue = lastMember.GetValue(penultimateValue, null);
                if (ReferenceEquals(oldValue, newValue) || newValue.IsUnsetValueOrDoNothing())
                {
                    return(false);
                }
            }
            else
            {
                oldValue = BindingConstants.UnsetValue;
                if (newValue.IsUnsetValueOrDoNothing())
                {
                    return(false);
                }
            }

            ValueAccessorChangingEventArgs args = null;

            if (ValueChanging != null)
            {
                args = RaiseValueChanging(context, penultimateValue, lastMember, oldValue, newValue);
                if (args != null)
                {
                    if (args.Cancel)
                    {
                        return(false);
                    }
                    if (!ReferenceEquals(newValue, args.NewValue))
                    {
                        newValue = args.NewValue;
                        if (newValue.IsUnsetValueOrDoNothing())
                        {
                            return(false);
                        }
                    }
                }
            }
            if (AutoConvertValue)
            {
                newValue = BindingServiceProvider.ValueConverter(lastMember.Type, newValue);
            }
            if (Equals(oldValue, newValue))
            {
                return(false);
            }
            if (lastMember.MemberType == BindingMemberType.Event)
            {
                TryRegisterEvent((BindingMemberValue)oldValue, newValue, context);
                RaiseValueChanged(context, penultimateValue, lastMember, oldValue, newValue, args);
            }
            else
            {
                if (_closure != null)
                {
                    _closure.Unsubscribe();
                }
                lastMember.SetValue(penultimateValue, new[] { newValue });
                if (ValueChanged != null)
                {
                    RaiseValueChanged(context, penultimateValue, lastMember, oldValue, newValue, args);
                }
            }
            return(true);
        }
Пример #11
0
        protected virtual IDataContext GetDataContext(View view, Context context, IAttributeSet attrs)
        {
            var dataContext = new DataContext();
            var strings     = ReadStringAttributeValue(context, attrs, Resource.Styleable.Binding, BindingAttrIndex);

            if (strings != null && strings.Count != 0)
            {
                dataContext.Add(ViewFactoryConstants.Bindings, strings);
            }

            SetAttributeValue(view, context, attrs, Resource.Styleable.ItemsControl,
                              Resource.Styleable.ItemsControl_ItemTemplate, AttachedMemberConstants.ItemTemplate, dataContext,
                              ViewFactoryConstants.ItemTemplateId);

            SetAttributeValue(view, context, attrs, Resource.Styleable.ItemsControl,
                              Resource.Styleable.ItemsControl_DropDownItemTemplate, AttachedMemberNames.DropDownItemTemplate,
                              dataContext,
                              ViewFactoryConstants.DropDownItemTemplateId);

            SetAttributeValue(view, context, attrs, Resource.Styleable.Control,
                              Resource.Styleable.Control_ContentTemplate, AttachedMemberConstants.ContentTemplate, dataContext,
                              ViewFactoryConstants.ContentTemplateId);

            SetAttributeValue(view, context, attrs, Resource.Styleable.Menu,
                              Resource.Styleable.Menu_MenuTemplate, AttachedMemberNames.MenuTemplate, dataContext,
                              ViewFactoryConstants.MenuTemplateId);


            SetAttributeValue(view, context, attrs, Resource.Styleable.Menu,
                              Resource.Styleable.Menu_PopupMenuTemplate, AttachedMemberNames.PopupMenuTemplate, dataContext,
                              ViewFactoryConstants.PopupMenuTemplateId);

            strings = ReadStringAttributeValue(context, attrs, Resource.Styleable.Menu,
                                               new[] { Resource.Styleable.Menu_PopupMenuEvent });
            if (strings != null && strings.Count > 0)
            {
                string eventName = strings[0];
                dataContext.Add(ViewFactoryConstants.PopupMenuEvent, eventName);
                IBindingMemberInfo member = BindingServiceProvider
                                            .MemberProvider
                                            .GetBindingMember(view.GetType(), AttachedMemberNames.PopupMenuEvent, false, false);
                if (member != null)
                {
                    member.SetValue(view, new object[] { eventName });
                }
            }

            strings = ReadStringAttributeValue(context, attrs, Resource.Styleable.Menu,
                                               new[] { Resource.Styleable.Menu_PlacementTargetPath });
            if (strings != null && strings.Count > 0)
            {
                string path = strings[0];
                dataContext.Add(ViewFactoryConstants.PlacementTargetPath, path);
                IBindingMemberInfo member = BindingServiceProvider
                                            .MemberProvider
                                            .GetBindingMember(view.GetType(), AttachedMemberNames.PlacementTargetPath, false, false);
                if (member != null)
                {
                    member.SetValue(view, new object[] { path });
                }
            }

            return(dataContext);
        }
Пример #12
0
 public object SetValue(object src, object[] args)
 {
     return(_member.SetValue(src, BindingReflectionExtensions.InsertFirstArg(args ?? MugenMvvmToolkit.Empty.Array <object>(), _indexes)));
 }
Пример #13
0
 private static void SetAdapter(AdapterView item, IAdapter adapter)
 {
     _rawAdapterMember.SetValue(item, new object[] { adapter });
 }
Пример #14
0
 private static void RefreshValue(object target, IBindingMemberInfo member)
 {
     member.SetValue(target, new[] { member.GetValue(target, null) });
 }