public override object ProvideValue(IServiceProvider serviceProvider)
        {
            string path = GetFilePath(RelativePath, DefaultTheme, CurrentTheme);

            if (path.IsNullOrEmpty())
            {
                return(null);
            }

            var provider  = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
            var type      = IProvideValueTargetExtensions.GetTargetType(provider);
            var converter = TypeDescriptor.GetConverter(type);

            return(converter.ConvertFrom(path));
        }
Example #2
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            string path = GetFilePath(RelativePath, DefaultTheme, CurrentTheme);

            if (path.IsNullOrEmpty())
            {
                return(null);
            }

            var provider  = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
            var type      = IProvideValueTargetExtensions.GetTargetType(provider);
            var converter = TypeDescriptor.GetConverter(type);

            try
            {
                return(converter.ConvertFrom(path));
            }
            catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(e, $"Failed to provide value for theme file {path}");
                return(null);
            }
        }
Example #3
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var binding = new Binding()
            {
                Source = Source,
                Path   = new PropertyPath(PathRoot + Path),
                Delay  = Delay,
                Mode   = Mode
            };

            if (TargetNullValue != null)
            {
                binding.TargetNullValue = TargetNullValue;
            }

            if (FallbackValue != null)
            {
                binding.FallbackValue = FallbackValue;
            }

            if (Converter != null)
            {
                binding.Converter = Converter;
            }

            if (ConverterParameter != null)
            {
                binding.ConverterParameter = ConverterParameter;
            }

            if (!StringFormat.IsNullOrEmpty())
            {
                binding.StringFormat = StringFormat;
            }

            var provider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;

            if (ServiceProvider.IsTargetTemplate(serviceProvider))
            {
                return(this);
            }
            else
            {
                var targetType = IProvideValueTargetExtensions.GetTargetType(provider);
                if (targetType == typeof(Visibility) && Converter == null)
                {
                    binding.Converter = new BooleanToVisibilityConverter();
                }

                if (provider.TargetProperty.GetType() == typeof(DependencyProperty))
                {
                    return(BindingOperations.SetBinding(
                               provider.TargetObject as DependencyObject,
                               provider.TargetProperty as DependencyProperty,
                               binding));
                }
                else
                {
                    if (targetType == typeof(BindingBase))
                    {
                        return(binding);
                    }
                }

                return(this);
            }
        }