Sinatr
Sinatr

Reputation: 21998

How to set fallback value for x:Static

Subj.

Can do like this to avoid having blurish view in design:

<Window.Effect>
    <BlurEffect Radius="{Binding Blur, FallbackValue=0}"/>
</Window.Effect>

But what about

<TextBlock ext="{x:Static local:App.Version}"/>

at design time auto-property App.Version is null. I can make it normal property and assign private field default value:

private static string _version = "Version1.0.0.0";
public static string Version { get { return _version; } }

Still there can be a situation when I want non-default value to be displayed. To example,

"Test long version string to be visible in designer only"

And yes, I understand, what Binding and Static are different in someway, yet, is there a way to achieve what I want? I also though to pass App.Version into ViewModel and bind View to it via Binding, but that's even worse (effort-wise), though more mvvm-conceptish.

Upvotes: 0

Views: 766

Answers (1)

amnezjak
amnezjak

Reputation: 2031

How about:

<TextBlock Text="{Binding Source={x:Static local:App.Version}, TargetNullValue='In designer'}" />

Note that you have to use TargetNullValue as FallbackValue is used when Binding cannot get value, which should not be the case for static property.

Upvotes: 3

Related Questions