protected override void OnParametersSet() { _backgroundColor = StyleContext.GetColorOrDefault(VariableNames.SwitchBackground, VariableNames.NeutralQuaternary); // Select first item if no value is selected if (Value == null && Items != null) { Value = Items.FirstOrDefault(); } // Ensure that a converter got supplied // -> Only required when the value is not of type "IOption" if (Converter == null && Items != null && Items is not IEnumerable <IOption> ) { throw new ApplicationException($"Cannot convert '{typeof(TItem).FullName}' to '{typeof(IOption).FullName}' without a converter."); } if (_iteratorUpdateRequired) { _iterator = new SelectIterator <TItem, IOption>(_items, Converter); } }
/// <summary> /// Projects each element of a sequence into a new form. /// </summary> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <typeparam name="TResult">The type of the value returned by <paramref name="selector"/>.</typeparam> /// <param name="source">A sequence of values to invoke a transform function on.</param> /// <param name="selector">A transform function to apply to each element.</param> /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param> /// <returns> /// An <see cref="IBindableCollection{TElement}"/> whose elements are the result of invoking the transform function on each element of <paramref name="source"/>. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="source"/> or <paramref name="selector"/> is null.</exception> public static IBindableCollection <TResult> Select <TSource, TResult>(this IBindableCollection <TSource> source, Expression <Func <TSource, TResult> > selector, DependencyDiscovery dependencyAnalysisMode) where TSource : class { source.ShouldNotBeNull("source"); selector.ShouldNotBeNull("selector"); var result = new SelectIterator <TSource, TResult>(source, selector.Compile(), source.Dispatcher); if (dependencyAnalysisMode == DependencyDiscovery.Enabled) { result = result.DependsOnExpression(selector.Body, selector.Parameters[0]); } return(result); }
protected override void OnParametersSet() { _backgroundColor = StyleContext.GetColorOrDefault(VariableNames.TabBarColor, VariableNames.NeutralSecondary); _activeBackgroundColor = StyleContext.GetColorOrDefault(VariableNames.TabBarActiveColor, VariableNames.ThemePrimary); // Ensure that a converter got supplied // -> Only required when the value is not of type "IIconOption" if (Converter == null && Items != null && Items is not IEnumerable <IIconOption> ) { throw new ApplicationException($"Cannot convert '{typeof(TItem).FullName}' to '{typeof(IIconOption).FullName}' without a converter."); } if (_iteratorUpdateRequired) { _iterator = new SelectIterator <TItem, IIconOption>(_items, Converter); } }