Return Value for DynamicResource

My application loads all lines from resource dictionaries defined in separate XAML files. It is possible that the DynamicResource key DynamicResource not exist at run time.

 <CheckBox Content="{DynamicResource myKeyThatIsMissing}"/> 

A regular binding has a Fallback value that can be used as follows:

 Text="{Binding StringToShow, FallbackValue=DefaultValue} 

Is it possible to have a default Fallback value for a property set with DynamicResource , which is used if the resource key does not exist?

+4
source share
1 answer

The System.Windows.DynamicResourceExtension class is unprinted, so perhaps you can extend it and add the desired logic by overriding the ProvideValue method.

Unfortunately, the default implementation returns an instance of the inner class ResourceReferenceExpression , so you may need to do some reflection or other magic to do this job.

0
source

Source: https://habr.com/ru/post/1437463/


All Articles