I can't get databinding to work within a DataTemplate
in Xamarin forms. I can get it to work with the ListView
(i.e. binding the RowHeight
), but once in the DataTemplate
, setting things to a property of my ViewModel has no affect.
In the below example, if I set the ColumnDefinition.Width
to a property, it is completely ignored, but setting it to a hard value works fine. I have put in a label to see what the property value is and it turns out blank when inside the Datatemplate
, and I have re-checked that the property is correct because if I take the label out of the Listview
, it displays the correct value.
Any ideas?
UPDATE:
My Class is "ParentPage" which has 2 properties: "Patients" and "Settings". Patients has an observable collection of "PatientList", How would I bind to the "Settings.Fontsize" shown below in the label. I have tried every combination I can think of:
<ListView x:Name="listView" ItemsSource="{Binding ParentPage.Patients.PatientsList}" RowHeight="{Binding ParentPage.Settings.RowHeight}" ><ListView.ItemTemplate><DataTemplate><ViewCell><Grid HorizontalOptions="FillAndExpand"><Grid.RowDefinitions><RowDefinition Height="*" /></Grid.RowDefinitions><Image Grid.Row="0" Grid.Column="0" Source="{Binding Picture}" /><Label TextColor="Red" Text="{Binding ParentPage.Settings.FontSize}" HorizontalOptions="Center" /></Grid> </ViewCell></DataTemplate></ListView.ItemTemplate></ListView>