Ejemplo n.º 1
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (ReferenceEquals(this.Binding, null)) return null;

            try
            {
                var context = DetermineContext(serviceProvider);

                if (String.IsNullOrEmpty(context))
                    Debug.WriteLine(String.Format("LocExtension: Could not find valid translation context for binding with path [{0}]. Please specify context explicitly", this.Binding.Path));

                IValueConverter converter = new LocalizationConverter(context, Localizer);
                if (!ReferenceEquals(this.Binding.Converter, null))
                {
                    var convGroup = new ConverterGroup();
                    convGroup.Converters.Add(this.Binding.Converter);
                    convGroup.Converters.Add(converter);
                    converter = convGroup;
                }
                this.Binding.Converter = converter;
                return this.Binding.ProvideValue(serviceProvider);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LocExtension: An exception occured while resolving translation for path [{0}]\r\n{1}\r\n{2}", this.Binding.Path, ex.Message, ex.StackTrace);
                return String.Format("[{0}]", this.Binding.Path);
            }
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (ReferenceEquals(this.Binding, null))
            {
                return(null);
            }

            try
            {
                var context = DetermineContext(serviceProvider);

                if (String.IsNullOrEmpty(context))
                {
                    Debug.WriteLine(String.Format("LocExtension: Could not find valid translation context for binding with path [{0}]. Please specify context explicitly", this.Binding.Path));
                }

                IValueConverter converter = new LocalizationConverter(context, Localizer);
                if (!ReferenceEquals(this.Binding.Converter, null))
                {
                    var convGroup = new ConverterGroup();
                    convGroup.Converters.Add(this.Binding.Converter);
                    convGroup.Converters.Add(converter);
                    converter = convGroup;
                }
                this.Binding.Converter = converter;
                return(this.Binding.ProvideValue(serviceProvider));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LocExtension: An exception occured while resolving translation for path [{0}]\r\n{1}\r\n{2}", this.Binding.Path, ex.Message, ex.StackTrace);
                return(String.Format("[{0}]", this.Binding.Path));
            }
        }