-
May 4th, 2010, 01:14 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] FallbackValue Binding
Can you have a FallbackValue be set to another property using data binding?
For example, I have a label that's default value will be coming from the DisplayName property however, if it's not populated I'd like to revert to the Name property on the same object.
Code:
<Label Grid.Column="0" Content="{Binding DisplayName, Mode=Default}"/>
-
May 5th, 2010, 01:49 PM
#2
Re: FallbackValue Binding
You could maybe use a Converter - dont know if you are familiar with them but basically using a Converter would mean that a specific method in your code gets called each time that binding is used and the value that is going to be used for the binding gets passed in to your code, so you could just check it and see if it is empty. If it is empty then you return the value of the Name property on whatever object you are talking about.
One situation where this might not work very well is if the object you are trying to bind to is not very easily accessible from your code (ie something automatically generated by a XAML DataTemplate or similar) - though I think it still would not be impossible, just a bit harder to get working reliably.
-
May 7th, 2010, 09:47 AM
#3
Thread Starter
Fanatic Member
Re: FallbackValue Binding
For those that are interested, I ended up having to create a IValueConverter to handle this situation.
-
May 7th, 2010, 01:05 PM
#4
Re: [RESOLVED] FallbackValue Binding
You mean exactly what I just described?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|