Bind more than one source properties to a target property in Vala?

30 views Asked by At

Say I have a GLib BindingGroup called location_binds which has properties city-name and country-name. I want to have a property that holds something like "City name, Country name".

I know that for binding one property I can use location_binds.bind ("city-name", this, "title", SYNC_CREATE) ("title" in this case would hold "City name"). But how about two (or any other number of) properties?

1

There are 1 answers

0
Ashkan Arabi On

My eventual solution was to use two variables. The first one bound normally:

location_binds.bind ("country-name", this, "country_name", SYNC_CREATE);

but the second one bound with a lambda expression that includes the first variable in its content:

location_binds.bind_property ("city-name", this, "title", SYNC_CREATE, (binding, src, ref target) => {
    string city_name = (string) src;
    title = "%s, %s".printf (city_name, this.country_name);
    target.set_string (title);
});