Reputation: 1217
In my Windows Phone 8 C#/XAML .NET 4.5 App I'm using databinding from ViewModel, which is working fine.
What I'd like is for a lozalized string from LocalizedResources to be displayed as a content of a button in the following cases:
The value returned by Binding is null
The binding could not be resolved
How could this be achieved?
What I've tried to do is:
(omitted TargetNullValue
, since the way to do it is probably going to be the same)
(for presentation purposes, i set the resource to be Applicationtitle)
<Button ... Content="{Binding Something, FallbackValue={Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}}" ... />
But what I get is text like System.Windows.Text.Data.Binding...
(can't read more since it's out of screen).
Did some googling/"stackoverflowing" and found something with valueconverters for WP7, that got me a bit puzzled.
(And added C# tag because I've got a feeling this is not going to be solved just by adding the right "property" to a tag/value to a "property", although I'd appreciate it to be)
Upvotes: 1
Views: 379
Reputation: 12465
I'm pretty sure you cannot apply binding to the FallbackValue. A very simple workaround is to check for null within your 'Something' property.
private string _something;
public string Something
{
get { return _something ?? AppResources.ApplicationTitle; }
set
{
_something = value;
OnPropertyChanged("Something");
}
}
Upvotes: 1