Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

XAML Bind One Label to Multiple Model Properties

$
0
0

I'm building a DataTemplate for use in a ListView and I'd like to have a label that is bound to multiple properties on the model.

public class SomeObject {

    public string Name { get; set; }
    public DateTime EffectiveDate { get; set; }
    public DateTime ExpirationDate { get; set; }

}

I would like to make a formatted string of EffectiveDate & ExpirationDate in the same label. So something like:
<Label Text="01/05/2015 - 02/18/2015" />

I have a XAML DataTemplate that looks something like this

    <DataTemplate>
        <ViewCell>
            <ViewCell.View>
                <StackLayout
                    Orientation="Vertical"
                    Padding="10, 10"
                    BackgroundColor="White">

                        <Label Text="{Binding Name}"/>

                        <Label Text="Binding EffectiveDate | ExpirationDate, Format={0} - {1}" />
                </StackLayout>
            </ViewCell.View>
        </ViewCell>
    </DateTemplate>

I would like to do a string format of EffectiveDate & ExpirationDate, but I'm not confident on how to get them in the same label. It seems an IConverter implementation might work, but I'm not 100% sure. I haven't been able to figure out how to pass the binding context to the ICoverter to format multiple properties (or if that's possible).


Viewing all articles
Browse latest Browse all 58056

Trending Articles