Is there a way to take advantage of the TargetNullValue of a binding using the Resx extension while supporting the dynamic culture switching feature of the CultureManager?

It's often times handy to specify a TargetNullValue on a binding to show an alternate value in something like a TextBlock or TextBox when the binding target value is null. It would be great to use this in conjunction with the Resx extension from Globalizer and allow that value to change when the culture is changed at runtime. But I haven't figured out a way to do it. Is this possible or any ideas for a workaround?

If you can put together a small sample project that demonstrates what you want to do (maybe by modifying one of our sample projects) then email a zipped copy to support@infralution.com. We will take a look and see if there is any way to achieve what you want._________________Infralution Support

I think I can describe the situation a little bit better here without a sample project. At least I'll try ...
(BTW, the code formatting feature doesn't seem to support any attributes in markup samples, so I had to replace the '<' and '>' characters with '[' and ']')

Say you have a regular string property on a ViewModel named "Description":

Code:

public string Description { get; set; } //This could be a full INPC property, doesn't matter

In your XAML, you might want to do something like this so that you display the value of the Description property in a TextBlock, unless the value is null in which case you show some other message to the user:

But like the ConverterParameter case, this won't work when switching cultures at runtime. It would be nice to be able to use the <Resx> element to achieve this by having a property, named something like BindingTargetNullValueKey, which would allow you to specify the Resx key for looking up the TargetNullValue for the binding when you recreate it. Does that make sense? If not, let me know and I'll put together a complete sample.

In the meantime, I've come up with a workaround involving a value converter that lets's me specify a resource key and the resource manager to use for looking up that key's value, which I can use with a normal binding to achieve this effect. A bit of infrastructure and extra markup when I need to use it, but it works. Would be nice to have it just built into the Resx extension though.

the code formatting feature doesn't seem to support any attributes in markup samples, so I had to replace the '<' and '>' characters with '[' and ']

If you check the "Disable HTML in this post" option then you can use XML elements like this:

Code:

<myattribute>
SomeCode

Quote:

It would be nice to be able to use the <Resx> element to achieve this by having a property, named something like BindingTargetNullValueKey, which would allow you to specify the Resx key for looking up the TargetNullValue for the binding when you recreate it. Does that make sense? If not, let me know and I'll put together a complete sample.

I think this may be possible. I will need sample to test any solution on - so it would certainly make things quicker from our end if you could put one together._________________Infralution Support

Don't worry about a sample project - I think I can replicate the behaviour you want with one of our sample projects - and the good news is that I think that we can add this feature to the ResxExtension. I will create a new version of the Infralution.Localization.Wpf assembly and put it on our website on Monday for you to try._________________Infralution Support

In this case the "_selectedTextBlock.Text" defines the resource key for a format string used to format (non-null) bound values and the "_selectedTextBlock.NullText" is the resource key to use for a null value. If you don't need to format the bound values then you can just leave the Key attribute out ie

Yep, works perfectly. That's exactly the behavior I was hoping for. Allows me to get rid of the somewhat clunky value converter I had created to work around this issue - much more elegant this way. Thanks!