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

Best way to bind multiple properties to controls like Labels using MVVM

$
0
0

Hi Guys,
This is kind of silly question may be, however this is puzzling to I guess everyone - every time.

I have a Viewmodel interacting with a service and pulling the information of a individual person's profile with around 30 properties.
I want to display this information in a non-interactive view (so far I assume 2-3 properties will be required to be editable in future)

I do not want to use the ListView with the custom item template (having 2 labels or something) and bind the data as key value pair because of 2 reasons.

  1. I wanted specific related properties (like Date of Birth and Gender) in one group or section and other specific properties like Education and University or such properties in other section, to be displayed (with section headers) to the end-user.
  2. Second reason is I want to use the model properties directly , not to convert them as key-value pair or hash-table like stuff before binding them to view elements.

My current implementation is (which is crude BTW, I would say, however works well)
is having all the labels laid on a flat view and bind the individual model properties to the label like

in ViewModel
private string _Full_Name;
public string Full_Name
{
get { return _Full_Name; }
set { SetProperty(ref _Full_Name, value); }
}
...... List goes on and on for like 30 properties

and in View I've displayed the values via a grid structure and label.

<Label Text="{Binding Full_Name}" Grid.Row="0" Grid.Column="1" />

However this seems too raw, I mean can we have some better way populate the labels dynamically.

(I thought of having a Binding Context at ContentPage level with ObservableCollection and creating/binding the label dynamically initially, however seems little tight spot with MVVM right now) - I welcome ideas on this path... :)

Can you guys please suggest any better approach?

Thanks,
N Baua


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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