/// <summary>
        /// Gets the culture set for the object.
        /// </summary>
        /// <returns>
        /// A <see cref="CultureInfo"/> or null if no explicit value is set for the object.
        /// </returns>
        public CultureInfo GetCulture()
        {
            var obj = Object;

            if (obj == null)
            {
                return(null);
            }

            CultureInfo result;

            if (obj.CheckAccess())
            {
                result = LocalizationScope.GetCulture(obj);
            }
            else
            {
                result = (CultureInfo)obj.Dispatcher.Invoke(new DispatcherOperationCallback(x => LocalizationScope.GetCulture((DependencyObject)x)), obj);
            }

            if (result == null)
            {
                // Get the culture of the UI thread in case the current thread is different
                result = obj.Dispatcher.Thread.CurrentCulture;
            }

            return(result);
        }
        /// <summary>
        /// Returns the localized value.
        /// </summary>
        /// <returns></returns>
        object ProduceValue(Type targetPropertyType, bool dataBound, object dataBoundValueOrValues)
        {
            Debug.Assert(targetPropertyType != null);

            var rootObject = this.RootObject;

            if (rootObject == null)
            {
                // The object has been GC
                return(TypeUtils.GetDefaultValue(targetPropertyType));
            }

            var dispatcher = rootObject.Dispatcher;

            var cultureInfo     = LocalizationScope.GetCulture(rootObject) ?? dispatcher.Thread.CurrentCulture;
            var uiCultureInfo   = LocalizationScope.GetUICulture(rootObject) ?? dispatcher.Thread.CurrentUICulture;
            var resourceManager = ResourceManagerHelper.GetResourceManager(rootObject);

            return(base.ProduceValue(
                       null,
                       targetPropertyType,
                       resourceManager,
                       cultureInfo,
                       uiCultureInfo,
                       dataBound,
                       dataBoundValueOrValues
                       ));
        }
예제 #3
0
        object ProduceValue(bool dataBound, object dataBoundValueOrValues)
        {
            var targetObject = this.TargetObject;

            if (targetObject == null)
            {
                // The object has been GC
                return(TargetProperty.DefaultValue);
            }

            var dispatcher      = targetObject.Dispatcher;
            var culture         = LocalizationScope.GetCulture(targetObject) ?? dispatcher.Thread.CurrentCulture;
            var uiCulture       = LocalizationScope.GetUICulture(targetObject) ?? dispatcher.Thread.CurrentUICulture;
            var resourceManager = ResourceManagerHelper.GetResourceManager(targetObject);

            return(base.ProduceValue(
                       TargetProperty,
                       TargetProperty.PropertyType,
                       resourceManager,
                       culture,
                       uiCulture,
                       dataBound,
                       dataBoundValueOrValues
                       ));
        }