Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Null Coalescense property binding

$
0
0

Basically, I want to setup a binding that behaves like the following C# code:

this.Text = Control1.Text.IsNotNullOrEmpty() ? Control1.Text : Control2.Text

So, I want to bind my "Text" property to "Control1.Text" property IF it is not null and not an empty string, otherwise I want to use the "Control2.Text" property. Because "Control2.Text" might change it's value, I can't just use it as a default value when creating the binding. I don't see a way to do this, but if somebody knows an out of the box way to do this that would be great.

I've looked at the Binding and BindingBase classes and don't see a way to build a custom subclass that would allow me to do what I want.

Therefore, I think the only way I can do this is to create a "helper class" something like:

public class DoubleBinding<T>
{
    public T Value1 { get; set; }
    public T Value2 { get; set; }

    public T Value { get; }
}

With some logic that sets Value to the proper value any time Value1 or Value2 change. Then I would bind Value1 to Control1.Text and Value2 to Control2.Text and bind this.Text to just the Value property.

Is that my best option or is there a better way to do this?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>