How to read controls values if inside ResourceDictionary?

JassimRahmaJassimRahma USMember ✭✭✭

Hi,

I have a calendar inside ResourceDictionary in the below code... How can I read the value of that calendar? I tried it the normal way but getting:

The name 'CalendarPrayerTimes' does not exist in the current context

Here is my code:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Jafaria.PrayerTimes"
    xmlns:SyncfusionCalendar="clr-namespace:Syncfusion.SfCalendar.XForms;assembly=Syncfusion.SfCalendar.XForms"
    xmlns:SyncfusionMaps="clr-namespace:Syncfusion.SfMaps.XForms;assembly=Syncfusion.SfMaps.XForms"
    xmlns:XamarinMaps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
    Title="مواقيت الصلاة">
    <ContentPage.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="PrayerTimeTemplate">
                <ContentView BackgroundColor="White" x:Name="PrayerTimeContentView">
                    <SyncfusionCalendar:SfCalendar x:Name="CalendarPrayerTimes" FlowDirection="RightToLeft" ShowHeader="true" OnHeaderLoaded="Handle_OnHeaderLoaded" MonthChanged="Handle_MonthChanged" Margin="20,20,20,20" SelectionChanged="Handle_SelectionChanged" />
                </ContentView>
            </DataTemplate>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Content>
    <Grid FlowDirection="RightToLeft" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="25">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    .....................................
    .....................................
    .....................................
    .....................................
    .....................................

Thanks,
Jassim

Best Answer

  • JassimRahmaJassimRahma US ✭✭✭
    Accepted Answer

    I managed to get it using:

    SfCalendar cal = (SfCalendar)sender;
    
    date = cal.SelectedDate;
    

Answers

  • wesleyfavarinwesleyfavarin USMember ✭✭

    Hello @JassimRahma your can try in you .cs get the name of your component

    try: var NewValueOfYourCalendar= ContentView.FindByName("CalendarPrayerTimes");

    Hope this helps! :)

  • JassimRahmaJassimRahma USMember ✭✭✭
    Accepted Answer

    I managed to get it using:

    SfCalendar cal = (SfCalendar)sender;
    
    date = cal.SelectedDate;
    
Sign In or Register to comment.