Пример #1
0
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="parameter">The parameter.</param>
        /// <returns>System.Object.</returns>
        protected override object Convert(object value, System.Type targetType, object parameter)
        {
            var parameterAsString = ObjectToStringHelper.ToString(parameter);

            var isSupported        = false;
            var supportedPlatforms = parameterAsString.Split(new[] { '|' });

            foreach (var supportedPlatform in supportedPlatforms)
            {
                KnownPlatforms platform = KnownPlatforms.Unknown;
                if (Enum <KnownPlatforms> .TryParse(supportedPlatform, out platform))
                {
                    if (Platforms.IsPlatformSupported(platform))
                    {
                        isSupported = true;
                        break;
                    }
                }
            }

            if (SupportInversionUsingCommandParameter && ConverterHelper.ShouldInvert(parameter))
            {
                isSupported = !isSupported;
            }

            return(isSupported);
        }
Пример #2
0
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type" /> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <returns>The value to be passed to the target dependency property.</returns>
        protected override object Convert(object value, Type targetType, object parameter)
        {
            var containsItems = false;

            if (value != null)
            {
                var collection = value as ICollection;
                if (collection != null && collection.Count > 0)
                {
                    containsItems = true;
                }

                var enumerable = value as IEnumerable;
                if (!containsItems && enumerable != null)
                {
                    // TODO: Would MoveNext + reset be better?
                    //var item = enumerable.GetEnumerator();
                    //item.

                    foreach (object obj in enumerable)
                    {
                        containsItems = true;
                        break;
                    }
                }
            }

            if (SupportInversionUsingCommandParameter && ConverterHelper.ShouldInvert(parameter))
            {
                containsItems = !containsItems;
            }

            return(containsItems);
        }
Пример #3
0
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type" /> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <returns>The value to be passed to the target dependency property.</returns>
        protected override object Convert(object value, Type targetType, object parameter)
        {
            bool isNull = value == null;
            bool invert = ConverterHelper.ShouldInvert(parameter);

            return(invert ? isNull : !isNull);
        }
Пример #4
0
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type" /> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <returns>The value to be passed to the target dependency property.</returns>
        protected override object Convert(object value, Type targetType, object parameter)
        {
            var isNull = value is null;

            if (SupportInversionUsingCommandParameter && ConverterHelper.ShouldInvert(parameter))
            {
                isNull = !isNull;
            }

            return(!isNull);
        }
Пример #5
0
        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI.
        /// </summary>
        /// <param name="value">The source data being passed to the target.</param>
        /// <param name="targetType">The <see cref="T:System.Type" /> of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <returns>The value to be passed to the target dependency property.</returns>
        protected override object Convert(object value, Type targetType, object parameter)
        {
            var isVisible = IsVisible(value, targetType, parameter);

            if (SupportInversionUsingCommandParameter && ConverterHelper.ShouldInvert(parameter))
            {
                isVisible = !isVisible;
            }

            return(isVisible ? Visibility.Visible : NotVisibleVisibility);
        }
        /// <summary>
        /// Determines what value this converter should return.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <returns>
        ///     <c>true</c> if the specified value is visible; otherwise, <c>false</c>.
        /// </returns>
        protected override bool IsVisible(object value, Type targetType, object parameter)
        {
            bool   invert      = ConverterHelper.ShouldInvert(parameter);
            string stringValue = value as string;

            if (invert)
            {
                return(string.IsNullOrEmpty(stringValue));
            }

            return(!string.IsNullOrEmpty(stringValue));
        }
        /// <summary>
        /// Convert Visibility back to bool.
        /// </summary>
        /// <param name="value">A value. Only value of type <see cref="T:System.Windows.Visibility" /> is supported,</param>
        /// <param name="targetType">A targettype, currently not used.</param>
        /// <param name="parameter">A parameter value, currently not used.</param>
        /// <returns>
        /// When value is Visibility.Visible then true else false.
        /// </returns>
        protected override object ConvertBack(object value, Type targetType, object parameter)
        {
            if (value is Visibility)
            {
                var isVisible = (Visibility)value == Visibility.Visible;

                // Note: base class will doesn't implement ConvertBack so we need to invert ourselves
                if (SupportInversionUsingCommandParameter && ConverterHelper.ShouldInvert(parameter))
                {
                    isVisible = !isVisible;
                }

                return(isVisible);
            }

            return(false);
        }
Пример #8
0
        /// <summary>
        /// Determines what value this converter should return.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <returns>
        ///     <c>true</c> if the specified value is visible; otherwise, <c>false</c>.
        /// </returns>
        protected override bool IsVisible(object value, Type targetType, object parameter)
        {
            bool invert = ConverterHelper.ShouldInvert(parameter);

            return(invert ? (value == null) : (value != null));
        }