Question

As we konw,if the key hadn't been found,it would raise an exception. But, is there a way to prevent this and just set the control's visibility to be Hidden?Or give it a FallbackValue just like Binding?

A simple example:
<TextBlock Text="{StaticResource myKey}"/>
Now "myKey" doesn't be defined,it'll raise an exception by default.But I wish I can set TextBlock's Visiblity to be hidden:
<TextBlock Text="nothing here" Visibilty="Hidden">
or:
<TextBlock Text="nothing here" FallbackValue="default value">(Notice:"FallbackValue" does'nt really exsit)
then the application could continue.Nothing wrong,cheers :)

Was it helpful?

Solution 2

A Simple implementation:
We can inherit StaticResourceExtension(Yeah,it's not sealed :)),then override ProvideValue method,return a default value.
Solved:)

OTHER TIPS

So far I could understand your question, you may put your code into a try clause, and catch exception.. It will atleast allow you to perform operation with the control. (Remember you may use finally clause for forceful execution) ..

If my assumption is wrong, I apologize in advance and request to be more specific :) good luck

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top