internal static Exception BindingMemberMustBeWriteable(IBindingMemberInfo member) { return new InvalidOperationException( string.Format("The binding member must be writeable, if it uses the SetValue method, path '{0}', type '{1}', member type '{2}', underlying member '{3}'", member.Path, member.Type, member.MemberType, member.Member)); }
/// <summary> /// Initializes a new instance of the <see cref="BindingActionValue" /> class. /// </summary> public BindingActionValue([NotNull] object memberSource, [NotNull] IBindingMemberInfo member) { Should.NotBeNull(memberSource, "memberSource"); Should.NotBeNull(member, "member"); _memberSource = ToolkitExtensions.GetWeakReference(memberSource); _member = member; }
internal static Exception InvalidEventSourceValue(IBindingMemberInfo member, object invalidValue) { return new InvalidOperationException( string.Format("The event binding member supports only method or command values, if it uses the SetValue method, path '{0}', type '{1}', member type '{2}', underlying member '{3}', invalid value '{4}'", member.Path, member.Type, member.MemberType, member.Member, invalidValue)); }
private static object GetListViewSelectedItem(IBindingMemberInfo bindingMemberInfo, ListView listView) { var items = listView.SelectedItems; if (items.Count == 0) return null; return ViewManager.GetDataContext(items[0]); }
public XamlUnresolvedResource(object target, string key, IBindingMemberInfo rootMember) { _key = key; _value = BindingConstants.UnsetValue; _reference = ServiceProvider.WeakReferenceFactory(target); _unsubscriber = rootMember.TryObserve(target, this); }
/// <summary> /// Called once for each element in the time of accession to obtain default values. /// </summary> private static string TextExtGetDefaultValue(TextView textBlock, IBindingMemberInfo bindingMemberInfo) { ServiceProvider .IocContainer .Get<IToastPresenter>() .ShowAsync("Invoking TextExtGetDefaultValue on " + textBlock.Id, ToastDuration.Short); return "Default value"; }
protected override void OnDetached() { Binding.SourceAccessor.ValueChanging -= SourceOnValueChanging; if (_subscriber != null) _subscriber.Dispose(); _subscriber = null; _member = null; }
public XamlResourceWrapper(object target, string key, IBindingMemberInfo rootMember, ISourceValue globalResource) { _key = key; _value = BindingConstants.UnsetValue; _reference = ServiceProvider.WeakReferenceFactory(target); _unsubscriber = rootMember.TryObserve(target, this); _globalResource = globalResource; }
public TabLayoutItemsSourceGenerator(TabLayout tabLayout) { _tabLayout = tabLayout; TryListenActivity(tabLayout.Context); _collectionViewManagerMember = BindingServiceProvider .MemberProvider .GetBindingMember(tabLayout.GetType(), AttachedMembers.ViewGroup.CollectionViewManager, false, false); }
/// <summary> /// Called once for each element in the time of accession to obtain default values. /// </summary> private static string TextExtGetDefaultValue(Label textBlock, IBindingMemberInfo bindingMemberInfo) { if (!ServiceProvider.DesignTimeManager.IsDesignMode) ServiceProvider .IocContainer .Get<IToastPresenter>() .ShowAsync("Invoking TextExtGetDefaultValue on " + textBlock.ClassId, ToastDuration.Short); return "Default value"; }
public MultiBindingPathMembers(WeakReference observerReference, object penultimateValue, IBindingPath path, IList <IBindingMemberInfo> members) { _observerRef = observerReference; _penultimateValueRef = ToolkitExtensions.GetWeakReference(penultimateValue); _path = path; _members = members; _lastMember = _members[_members.Count - 1]; }
private static void SetTableViewSelectedItem(IBindingMemberInfo bindingMemberInfo, UITableView uiTableView, object arg3) { var tableViewSource = uiTableView.Source as TableViewSourceBase; if (tableViewSource != null) { tableViewSource.SelectedItem = arg3; } }
private static void RaiseAttachedProperty(IBindingMemberInfo member, TTarget target, object o) { var property = ServiceProvider.AttachedValueProvider.GetValue <AttachedProperty <TTarget, TType> >(target, ((IAttachedBindingMemberInternal)member).Id, false); if (property != null) { property.RaiseWithMemberChanged(target, o); } }
private static void UpdateMember(ref IBindingMemberInfo member, object target, string path) { var type = target.GetType(); if (member == null || member.Member == null || member.Member.DeclaringType != type) { member = BindingServiceProvider.MemberProvider.GetBindingMember(type, path, true, true); } }
public PreferenceItemsSourceGenerator(PreferenceGroup preference) { Should.NotBeNull(preference, nameof(preference)); _preference = preference; _collectionViewManagerMember = BindingServiceProvider .MemberProvider .GetBindingMember(preference.GetType(), AttachedMembers.PreferenceGroup.CollectionViewManager, false, false); TryListenActivity(preference.Context); }
private static void SetCollectionViewSelectedItem(IBindingMemberInfo bindingMemberInfo, UICollectionView collectionView, object arg3) { var source = collectionView.Source as CollectionViewSourceBase; if (source != null) { source.SelectedItem = arg3; } }
public static object Convert(IBindingMemberInfo member, Type type, object value) #endif { if (value == null) { return(type.GetDefaultValue()); } if (type.IsInstanceOfType(value)) { return(value); } #if !WINDOWS_UWP && !NETFX_CORE #if XAMARIN_FORMS var converter = GetTypeConverter(type, member); #else var converter = GetTypeConverter(type, member.Member as MemberInfo); #endif if (converter != null && converter.CanConvertFrom(value.GetType())) { return(converter.ConvertFrom(value)); } #endif #if NETFX_CORE #if XAMARIN_FORMS if (ConvertibleTypes.Contains(value)) #else if (BindingExtensions.IsConvertible(value)) #endif #else if (value is IConvertible) #endif { return(System.Convert.ChangeType(value, type.GetNonNullableType(), BindingServiceProvider.BindingCultureInfo())); } #if WINDOWS_UWP || NETFX_CORE if (type.GetTypeInfo().IsEnum) #else if (type.IsEnum) #endif { #if WINDOWS_UWP || NETFX_CORE var s = value as string; if (s != null) { return(Enum.Parse(type, s, false)); } #endif return(Enum.ToObject(type, value)); } if (type == typeof(string)) { return(value.ToString()); } return(value); }
public ValueAccessorChangedEventArgs(IDataContext context, object penultimateValue, IBindingMemberInfo lastMember, object oldValue, object newValue) : base(oldValue, newValue) { Should.NotBeNull(context, "context"); Should.NotBeNull(lastMember, "lastMember"); _context = context; _penultimateValue = penultimateValue; _lastMember = lastMember; }
private static object GetCollectionViewSelectedItem(IBindingMemberInfo bindingMemberInfo, UICollectionView collectionView) { var source = collectionView.Source as CollectionViewSourceBase; if (source == null) { return(null); } return(source.SelectedItem); }
private static object TabLayoutGetSelectedItem(IBindingMemberInfo bindingMemberInfo, TabLayout tabLayout) { var p = tabLayout.SelectedTabPosition; if (p < 0) { return(null); } return(tabLayout.GetTabAt(p).DataContext()); }
private static IDisposable ObserveVisiblityMember(IBindingMemberInfo bindingMemberInfo, UIElement uiElement, IEventListener arg3) { #if WINDOWS_UWP return(DependencyPropertyBindingMember.ObserveProperty(uiElement, UIElement.VisibilityProperty, arg3)); #elif WINDOWSCOMMON || WINDOWS_PHONE return(new DependencyPropertyBindingMember.DependencyPropertyListener(uiElement, "Visibility", arg3)); #else return(new DependencyPropertyBindingMember.DependencyPropertyListener(uiElement, UIElement.VisibilityProperty, arg3)); #endif }
private static object GetSelectedItemTabControl(IBindingMemberInfo bindingMemberInfo, TabControl tabControl) { if (tabControl.TabCount == 0 || tabControl.SelectedIndex < 0) { return(null); } return(BindingServiceProvider .ContextManager .GetBindingContext(tabControl.TabPages[tabControl.SelectedIndex]).Value); }
private static object GetTableViewSelectedItem(IBindingMemberInfo bindingMemberInfo, UITableView uiTableView) { var tableViewSource = uiTableView.Source as TableViewSourceBase; if (tableViewSource == null) { return(null); } return(tableViewSource.SelectedItem); }
protected TableViewSourceBase([NotNull] UITableView tableView, string itemTemplate = AttachedMemberConstants.ItemTemplate) { Should.NotBeNull(tableView, "tableView"); _selectedItems = new HashSet <object>(); _tableView = tableView; _itemTemplateMember = BindingServiceProvider .MemberProvider .GetBindingMember(tableView.GetType(), itemTemplate, false, false); }
private static IEnumerable <object> GetErrors(IBindingMemberInfo bindingMemberInfo, object o) { var errorProvider = BindingServiceProvider.ErrorProvider; if (errorProvider == null) { return(Empty.Array <object>()); } return(errorProvider.GetErrors(o, string.Empty, DataContext.Empty)); }
private static object GetSelectedItemDataGridView(IBindingMemberInfo bindingMemberInfo, DataGridView dataGridView) { var row = dataGridView.CurrentRow; if (row == null) { return(null); } return(row.DataBoundItem); }
internal ViewGroupItemsSourceGenerator([NotNull] ViewGroup viewGroup) { Should.NotBeNull(viewGroup, nameof(viewGroup)); _viewGroup = viewGroup; _adapter = ItemsSourceAdapter.Factory(viewGroup, viewGroup.Context, Context); _collectionViewManagerMember = BindingServiceProvider .MemberProvider .GetBindingMember(viewGroup.GetType(), AttachedMembers.ViewGroup.CollectionViewManager, false, false); TryListenActivity(viewGroup.Context); }
private static object GetListViewSelectedItem(IBindingMemberInfo bindingMemberInfo, ListView listView) { var items = listView.SelectedItems; if (items.Count == 0) { return(null); } return(ViewManager.GetDataContext(items[0])); }
private static object GetRootMember(IBindingMemberInfo member, object o, object[] arg3) { var rootMember = BindingServiceProvider.VisualTreeManager.GetRootMember(o.GetType()); if (rootMember == null) { return(null); } return(rootMember.GetValue(o, arg3)); }
private static IDisposable ObserveRootMember(IBindingMemberInfo member, object o, IEventListener arg3) { var rootMember = BindingServiceProvider.VisualTreeManager.GetRootMember(o.GetType()); if (rootMember == null) { return(null); } return(rootMember.TryObserve(o, arg3)); }
private static object FindByNameControlMember(IBindingMemberInfo bindingMemberInfo, Control control, object[] arg3) { var root = WinFormsToolkitExtensions.GetRootControl(control); if (root != null) { control = root; } return(control.Controls.Find((string)arg3[0], true).FirstOrDefault()); }
private static object FindByNameMemberToolStripItem(IBindingMemberInfo bindingMemberInfo, ToolStripItem target, object[] arg3) { Control control = GetOwner(target); if (control == null) { return(null); } return(FindByNameControlMember(null, control, arg3)); }
protected virtual IBindingContext CreateBindingContext([NotNull] object item) { IBindingMemberInfo member = GetExplicitDataContextMember(item); if (member == null) { return(new BindingContext(item)); } return(new BindingContextSource(item, member)); }
/// <summary> /// Detaches this instance from its associated binding. /// </summary> protected override void OnDetached() { Binding.SourceAccessor.ValueChanging -= SourceOnValueChanging; if (_subscriber != null) { _subscriber.Dispose(); } _subscriber = null; _member = null; }
private static bool MenuItemUpdateActionView(IBindingMemberInfo bindingMemberInfo, IMenuItem menuItem, object content) { var actionView = menuItem.GetActionView(); if (actionView != null) { ParentObserver.Set(actionView, null); } object template = menuItem.GetBindingMemberValue(AttachedMembers.MenuItem.ActionViewTemplateSelector)?.SelectTemplate(content, menuItem); if (template != null) { content = template; } if (content == null) { #if APPCOMPAT MenuItemCompat.SetActionView(menuItem, null); #else menuItem.SetActionView(null); #endif return(true); } LayoutInflaterResult result = null; int viewId; if (int.TryParse(content.ToString(), out viewId)) { result = GetContextFromItem(menuItem).GetBindableLayoutInflater().InflateEx(viewId, null, false); content = result.View; } actionView = content as View; if (actionView == null) { Type viewType = TypeCache <View> .Instance.GetTypeByName(content.ToString(), true, true); actionView = viewType.CreateView(GetContextFromItem(menuItem)); } #if APPCOMPAT MenuItemCompat.SetActionView(menuItem, actionView); #else menuItem.SetActionView(actionView); #endif ParentObserver.Set(actionView, menuItem); var bindings = GetActionViewBind(menuItem); if (!string.IsNullOrEmpty(bindings)) { BindingServiceProvider.BindingProvider.CreateBindingsFromString(actionView, bindings, null); } result?.ApplyBindings(); return(true); }
private static LoadingOverlay CreateLoadingOverlay(UIView uiView, IBindingMemberInfo bindingMemberInfo) { // Determine the correct size to start the overlay (depending on device orientation) var bounds = UIScreen.MainScreen.Bounds; // portrait bounds if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight) { bounds.Size = new CGSize(bounds.Size.Height, bounds.Size.Width); } return new LoadingOverlay(bounds); }
internal ActionBarTabItemsSourceGenerator(ActionBar actionBar, ActionBarTabTemplate tabTemplate) { Should.NotBeNull(actionBar, "actionBar"); Should.NotBeNull(tabTemplate, "tabTemplate"); _actionBar = actionBar; _tabTemplate = tabTemplate; _collectionViewManagerMember = BindingServiceProvider .MemberProvider .GetBindingMember(actionBar.GetType(), AttachedMembers.ActionBar.CollectionViewManager, false, false); TryListenActivity(_actionBar.ThemedContext); }
private static void SetSelectedItemTabControl(IBindingMemberInfo bindingMemberInfo, TabControl tabControl, object item) { foreach (TabPage tabPage in tabControl.TabPages) { if (Equals(tabPage.DataContext(), item)) { tabControl.SelectedTab = tabPage; break; } } }
public DataTemplateProvider([NotNull] object container, [NotNull] string templateSelectorMember) { Should.NotBeNull(container, "container"); Should.NotBeNull(templateSelectorMember, "templateSelectorMember"); var type = container.GetType(); _container = container; _templateSelectorMember = BindingServiceProvider.MemberProvider.GetBindingMember(type, templateSelectorMember, false, false); if (_templateSelectorMember != null) _templateSelectorMember.TryObserve(container, this); UpdateValues(); }
internal ActionBarTabItemsSourceGenerator(ActionBar actionBar, ActionBarTabTemplate tabTemplate) { Should.NotBeNull(actionBar, nameof(actionBar)); Should.NotBeNull(tabTemplate, nameof(tabTemplate)); _actionBar = actionBar; _tabTemplate = tabTemplate; _collectionViewManagerMember = BindingServiceProvider .MemberProvider .GetBindingMember(actionBar.GetType(), AttachedMembers.ActionBar.CollectionViewManager, false, false); TryListenActivity(_actionBar.ThemedContext); }
/// <summary> /// Initializes a new instance of the <see cref="DataTemplateProvider" /> class. /// </summary> public DataTemplateProvider([NotNull] object container, [NotNull] string templateIdMember, [NotNull] string templateSelectorMember) { Should.NotBeNull(container, "container"); Should.NotBeNull(templateIdMember, "templateIdMember"); Should.NotBeNull(templateSelectorMember, "templateSelectorMember"); var type = container.GetType(); _container = container; _templateIdMember = BindingServiceProvider.MemberProvider.GetBindingMember(type, templateIdMember, false, false); _templateSelectorMember = BindingServiceProvider.MemberProvider.GetBindingMember(type, templateSelectorMember, false, false); }
public DataTemplateProvider([NotNull] object container, [NotNull] string templateSelectorMember) { Should.NotBeNull(container, nameof(container)); Should.NotBeNull(templateSelectorMember, nameof(templateSelectorMember)); var type = container.GetType(); _container = container; _templateSelectorMember = BindingServiceProvider.MemberProvider.GetBindingMember(type, templateSelectorMember, false, false); _templateSelectorMember?.TryObserve(container, this); UpdateValues(); }
private static void SetIsActionViewExpanded(IBindingMemberInfo bindingMemberInfo, IMenuItem menuItem, bool value) { if (value) { menuItem.ExpandActionView(); } else { menuItem.CollapseActionView(); } }
/// <summary> /// Called once for each element in the time of accession to obtain default values. /// </summary> private static string TextExtGetDefaultValue(UILabel textBlock, IBindingMemberInfo bindingMemberInfo) { if (!ServiceProvider.DesignTimeManager.IsDesignMode) { ServiceProvider .IocContainer .Get <IToastPresenter>() .ShowAsync("Invoking TextExtGetDefaultValue on " + textBlock.AccessibilityLabel, ToastDuration.Short); } return("Default value"); }
/// <summary> /// Attaches to the specified binding. /// </summary> protected override bool OnAttached() { object value = Binding.TargetAccessor.Source.GetPathMembers(false).PenultimateValue; if (value == null || value.IsUnsetValue()) return false; _member = BindingServiceProvider .MemberProvider .GetBindingMember(value.GetType(), AttachedMemberConstants.Focused, false, false); if (_member == null) return false; _subscriber = _member.TryObserve(value, this); if (_subscriber == null) return false; Binding.SourceAccessor.ValueChanging += SourceOnValueChanging; return true; }
public BindingPathMembersMock(object source, IBindingPath path, IBindingMemberInfo member) { Source = source; PenultimateValue = source; Path = path; if (member == null || source == null) { AllMembersAvailable = false; LastMember = BindingMemberInfo.Unset; _members = Empty.Array<IBindingMemberInfo>(); } else { AllMembersAvailable = true; LastMember = member; } }
internal ItemsSourceGenerator([NotNull] object view) { Should.NotBeNull(view, "view"); #if WINFORMS ListenDisposeEvent(view as IComponent); _isTabControl = view is TabControl; #elif TOUCH TryListenController(view as INativeObject); #endif _view = ServiceProvider.WeakReferenceFactory(view); var type = view.GetType(); _itemTemplateMember = BindingServiceProvider .MemberProvider .GetBindingMember(type, AttachedMemberConstants.ItemTemplate, false, false); _collectionViewManagerMember = BindingServiceProvider .MemberProvider .GetBindingMember(type, "CollectionViewManager", false, false); }
private static void SetListViewSelectedItem(IBindingMemberInfo bindingMemberInfo, ListView listView, object value) { //Clear selection foreach (ListViewItem item in listView.SelectedItems) { item.Focused = false; item.Selected = false; } if (value == null) return; foreach (ListViewItem item in listView.Items) { if (Equals(ViewManager.GetDataContext(item), value)) { item.Focused = true; item.Selected = true; break; } } }
protected CollectionViewSourceBase([NotNull] UICollectionView collectionView, string itemTemplate = AttachedMemberConstants.ItemTemplate) { Should.NotBeNull(collectionView, "collectionView"); _collectionView = PlatformExtensions.CreateWeakReference(collectionView); _itemTemplateMember = BindingServiceProvider.MemberProvider.GetBindingMember(collectionView.GetType(), itemTemplate, false, false); var controllerView = collectionView.FindParent<IViewControllerView>(); if (controllerView != null && !(controllerView is IMvvmNavigationController)) { _listener = ReflectionExtensions.CreateWeakEventHandler<CollectionViewSourceBase, EventArgs>(this, (adapter, o, arg3) => adapter.OnDisposeController(o, arg3)); controllerView.Mediator.DisposeHandler += _listener.Handle; } UseAnimations = collectionView .GetBindingMemberValue(AttachedMembers.UICollectionView.UseAnimations) .GetValueOrDefault(true); ScrollPosition = collectionView .GetBindingMemberValue(AttachedMembers.UICollectionView.ScrollPosition) .GetValueOrDefault(UICollectionViewScrollPosition.Top); }
private object GetSourceValue(IBindingMemberInfo targetMember, IDataContext context, bool throwOnError) { object value = GetRawValueInternal(targetMember, context, throwOnError); if (value.IsDoNothing()) return BindingConstants.DoNothing; if (_parameters.ConverterDelegate != null && !value.IsUnsetValue()) { IBindingValueConverter converter = _parameters.ConverterDelegate(context); if (converter != null) { CultureInfo culture = _parameters.ConverterCultureDelegate.GetValueOrDefault(context, CultureInfo.CurrentCulture); object parameter = _parameters.ConverterParameterDelegate.GetValueOrDefault(context); value = converter.Convert(value, targetMember.Type, parameter, culture, context); } } if (value.IsUnsetValue()) value = _parameters.FallbackDelegate.GetValueOrDefault(context) ?? targetMember.Type.GetDefaultValue(); if (value == null) return _parameters.TargetNullValue; return value; }
private object GetTargetValue(IBindingMemberInfo targetMember, IDataContext context, bool throwOnError) { object value = GetRawValueInternal(targetMember, context, throwOnError); if (value.IsUnsetValueOrDoNothing()) return value; if (_parameters.ConverterDelegate != null) { IBindingValueConverter converter = _parameters.ConverterDelegate(context); if (converter != null) { CultureInfo culture = _parameters.ConverterCultureDelegate.GetValueOrDefault(context, CultureInfo.CurrentCulture); object parameter = _parameters.ConverterParameterDelegate.GetValueOrDefault(context); value = converter.ConvertBack(value, targetMember.Type, parameter, culture, context); } } if (Equals(value, _parameters.TargetNullValue)) return null; return value; }
/// <summary> /// Gets the source value. /// </summary> protected virtual object GetValueInternal(IBindingMemberInfo targetMember, IDataContext context, bool throwOnError) { if (_parameters == null) return GetRawValueInternal(targetMember, context, throwOnError); if (_isTarget) return GetTargetValue(targetMember, context, throwOnError); return GetSourceValue(targetMember, context, throwOnError); }
/// <summary> /// Gets the raw value from source. /// </summary> protected abstract object GetRawValueInternal(IBindingMemberInfo targetMember, IDataContext context, bool throwOnError);
/// <summary> /// Gets the source value. /// </summary> /// <param name="targetMember">The specified member to set value.</param> /// <param name="context">The specified operation context.</param> /// <param name="throwOnError"> /// true to throw an exception if the value cannot be obtained; false to return /// <see cref="BindingConstants.InvalidValue" /> if the value cannot be obtained. /// </param> public object GetValue(IBindingMemberInfo targetMember, IDataContext context, bool throwOnError) { try { var value = GetValueInternal(targetMember, context, throwOnError); if (value.IsUnsetValue()) return targetMember.Type.GetDefaultValue(); return value; } catch (Exception) { if (throwOnError) throw; return BindingConstants.InvalidValue; } }
private static IDisposable ObserveTextTextBlock(IBindingMemberInfo bindingMemberInfo, TextBlock textBlock, IEventListener arg3) { #if WINDOWS_UWP return DependencyPropertyBindingMember.ObserveProperty(textBlock, TextBlock.TextProperty, arg3); #else return new DependencyPropertyBindingMember.DependencyPropertyListener(textBlock, "Text", arg3); #endif }
private static IDisposable ObserveParentMember(IBindingMemberInfo bindingMemberInfo, FrameworkElement o, IEventListener arg3) { return ParentObserver.GetOrAdd(o).AddWithUnsubscriber(arg3); }
private static void SetParentValue(IBindingMemberInfo bindingMemberInfo, FrameworkElement frameworkElement, object arg3) { ParentObserver.GetOrAdd(frameworkElement).Parent = arg3; }
private static object GetParentValue(IBindingMemberInfo bindingMemberInfo, FrameworkElement target) { return ParentObserver.GetOrAdd(target).Parent; }