- Home
- Forum
- Xamarin.Forms
- How can I reference more than one timepicker in a collectionview
How can I reference more than one timepicker in a collectionview
Hi I have a collectionview with [days of the week, a checkbox, and a SFtimepicker]. My xaml code for the collection view looks like this:
<CollectionView x:Name="RepeatCollectionView" HorizontalOptions="Center" ItemsSource="{Binding DayList}" HeightRequest="320">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="0" RowDefinitions="45" ColumnDefinitions="*,*">
<Label Text="{Binding Day}" FontAttributes="Bold" FontSize="Medium"
Margin="30,0"
VerticalTextAlignment="Center" HorizontalTextAlignment="Start"/>
<CheckBox x:Name="SelectDayCheckBox" Grid.Row="0" Grid.Column="1" HorizontalOptions="Start" IsChecked="{Binding Selected, Mode=TwoWay}" BindingContext="{Binding .}" CheckedChanged="SelectDayCheckBox_CheckedChanged"/>
<inputLayout:SfTextInputLayout
Margin="30, 0"
Hint="Select a Time"
OutlineCornerRadius="8"
ContainerBackgroundColor="Transparent" Grid.Column="1">
<Grid VerticalOptions="Center" HeightRequest="60">
<Label VerticalOptions="Center" FontFamily="SecondFont" VerticalTextAlignment="Center" x:Name="DateEntry" IsEnabled="False" TextColor="Red"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped_1"/>
</Grid.GestureRecognizers>
</Grid>
</inputLayout:SfTextInputLayout>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
My problem is I am able to open the timer but how am I to reference the SfTextInputLayout-Label which opens the timepicker? I am unable to show the user the time they selected.
i have this as my timepicker ok button:
private void date_OkButtonClicked(object sender, Syncfusion.SfPicker.XForms.SelectionChangedEventArgs e)
{
var selectedItem = date.SelectedItem as ObservableCollection<object>;
string hour = selectedItem[0].ToString();
string min = selectedItem[1].ToString();
string AmPm = selectedItem[2].ToString();
DateEntry.Text = hour + ":" + min + " " + AmPm;
}
but the name DateEntry does not exsist in the current context
Than
Greetings from Syncfusion.
We have validated your query and created sample based on your code snippet to achieve your requirement. Please find the sample from below link.
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/TimePickerSample1113295699
In this sample, we have binded the view model property to the DateEntry Label text to display the selected time from time picker.
Please check with the above sample and let us know if you have any concern.
Regards
Jeya K
Thanks this works