Binding sub property

Hi,
I've got a problem when I try to bind a sub property of my class.

Here's how I bind my property and the nested property:

<AbsoluteLayout> <Image Source="{Binding act_logo}" AbsoluteLayout.LayoutBounds="0, .2, 1, .5" AbsoluteLayout.LayoutFlags="All" /> <Label Text="{Binding act_profile.firstname}" FontSize="8" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds=".5, .8, 1, .3" AbsoluteLayout.LayoutFlags="All" /> </AbsoluteLayout>

The binding of act_logo work perfectly but the binding of act_profile.firstname doesn't word. Can somebody explain me why ?

Here's my class:

public class Smk_Account { public string _id; public string act_login; public string act_password; public string act_email; public Profile act_profile { get; set; } public Media[] medias; public string[] roles; public DateTime act_update; public string act_tokenAccess; public ImageSource act_logo { get; set; } = ImageSource.FromFile("profile.png");

and the class Profile:

public class Profile { public string city; public string postal_code; public string address; public string birthdate; public string mobile; public string firstname; public string lastname; }

Tagged:

Posts

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I don't see you have set the Label's BindingContext

  • CFraisseCFraisse FRMember
    edited September 2016

    I began Xamarin three months ago and I'm really a beginner with binding.*
    I don't set the binding context of the label because this label (and the image too) are in a viewcell in my listview. And this listview has an ObservableCollection of Smk_Account for ItemSource, that's why in my opinion (tell me if I'm wrong) every cell of my listview are binded to an Smk_Account, otherwise how could the act_logo binding work ?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Yes, should be. Have you some warnings in your Output tab when you run the app? Try to visualize another property like 'act_email'

  • CFraisseCFraisse FRMember
    edited September 2016

    I've no warning and when I try with act_email it doesn't work too.
    How could the binding works for the image but doesn't for the label ?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    What does it means 'it does not work'? Has it a value?

  • CFraisseCFraisse FRMember

    I can't see anything so my label should be empty. Because if I do Label.Text="Test", I can see the text "Test" on my app

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you have a binding problem. Do you set listview. ItemSource?

  • CFraisseCFraisse FRMember

    yes I set it in my .xaml.cs

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Have you rows in your listview?

  • CFraisseCFraisse FRMember

    Rows ?
    Here's my Listview:
    <ListView x:Name="memberList" BackgroundColor="#DEDEDE" Rotation="270" RowHeight="60" SeparatorVisibility="None" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=-30}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=-0.5, Constant=30}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=Constant, Constant=60}" RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ContentView Rotation="90" Padding="1" TranslationX="60"> <AbsoluteLayout> <Image Source="{Binding act_logo}" AbsoluteLayout.LayoutBounds="0, .2, 1, .5" AbsoluteLayout.LayoutFlags="All" /> <Label Text="{Binding act_email}" FontSize="8" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" AbsoluteLayout.LayoutBounds=".5, .8, 1, .3" AbsoluteLayout.LayoutFlags="All" /> </AbsoluteLayout> </ContentView> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    edited September 2016

    Yes Rows. Listview usually visualize rows. Do you see rows in your listview or it's empty? If you visually rows, ItemSource works well and I think it's a empty value problem

  • CFraisseCFraisse FRMember
    edited September 2016

    I can see my picture "act_logo" so the rows are visible. I don't know if it's empty actually but I think so because nothing is displayed where my label should be.
    Strange thing if I had the property x:Name="firstnameLabel" to my label to be able to print something like Debug.WriteLine("{0}", firstnameLabel.Text); it said "the name 'firstnameLabel' does not exist in the namespace" so I can't be shure that my label is empty

  • CFraisseCFraisse FRMember
    edited September 2016

    Oh my bad I'm really sorry but it works with act_email, it's because I didn't add the {get; set;} in my class that it didn't work so the binding is working but not with act_profile.firstname

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Maybe you have to add GetSet everywhere?

  • CFraisseCFraisse FRMember

    I'll try

  • CFraisseCFraisse FRMember
    edited September 2016

    It was that... thank you so much !!

Sign In or Register to comment.