We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cannot Refresh SfSchedule

Thread ID:

Created:

Updated:

Platform:

Replies:

151200 Feb 3,2020 02:44 PM UTC Feb 10,2020 08:55 AM UTC Xamarin.Forms 10
loading
Tags: SfSchedule
George
Asked On February 3, 2020 02:44 PM UTC

Hi,
I have a tabbed page with 2 children.
ChildPage 1 has a SfScheduler with datasource binding an observable collection at SchedulerViewModel 
Observable collection gets filled with Appointment data from the webapi server.
I also have a SignalR Service.

Scenario
When a message arrives from the server SignalR Service catches the message and the app fetches all new appointments and show them on the 
scheduler of childPage1 
 
I can not figure out how to do this.
I have tried several approaches without success.

Code Snippet

SchedulerPage.xaml.cs 
public SchedulerPage ()
{
InitializeComponent ();
            BindingContext =schedulerviewModel= new SchedulerViewModel();
}

SchedulerPage.xaml
<syncfusion:SfSchedule x:Name="schedule"
                                       DataSource="{Binding AppointmentEventsCollection}"
                                       ScheduleView = "WeekView"
                                       HeaderHeight="0"
                                       Grid.Row="0"
                                       HorizontalOptions="EndAndExpand"
                                       VerticalOptions="FillAndExpand"                                       
                                       FirstDayOfWeek="2"
                                       TimeInterval="30">


SchedulerViewModel.cs
public class SchedulerViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
private CustomAppointments appointmentEvents = new CustomAppointments();
        private ObservableCollection<CustomAppointments> _AppointmentEventsCollection = new ObservableCollection<CustomAppointments>();
        public ObservableCollection<CustomAppointments> AppointmentEventsCollection
        {
            get
            {
                return _AppointmentEventsCollection;
            }
            set
            {
                _AppointmentEventsCollection = value;
                OnPropertyChanged("AppointmentEventsCollection");
            }
        }

public SchedulerViewModel()
        {
            AppointmentEventsCollection = new ObservableCollection<CustomAppointments>();
            GetAppointmentsAndFillObservable(appointmentEvents);
        }

SignaRServices.cs
private async Task OnMessageReceived(SignalRMessages message)
        {
//Here I need to refresh the AppointmentEventsCollection
// wich is the DataSource of the scheduler 
}

Thank you for any help

Karthikraja Arumugam [Syncfusion]
Replied On February 4, 2020 01:25 PM UTC

Hi George, 
 
Thank you for contacting Syncfusion support. 
 
Based on the shared information we have checked your requirement. Since you are trying to access Schedule or Schedule binding context from other class you need Schedule instance, for this use a public property in SchedulerPage which will return Schedule object and in your SignalRService class using the public Schedule object get the binding context and assign new DataSource to it. 
 
Please refer the following code example for the same, 
//Schedule page 
    public partial class MainPage : ContentPage 
    { 
        public MainPage() 
        { 
            InitializeComponent(); 
        } 
 
        public SfSchedule Schedule 
        { 
            get { return this.schedule; } 
        }  
    } 
 
// Set DataSource  
        private void Bindable_Clicked(object sender, EventArgs e) 
        { 
            ScheduleAppointmentCollection scheduleAppointments = new ScheduleAppointmentCollection(); 
            scheduleAppointments.Add(new ScheduleAppointment 
            { 
                StartTime = new DateTime(2020, 2, 4, 10, 0, 0), 
                EndTime = new DateTime(2020, 2, 4, 11, 0, 0), 
                Subject = "Meeting" 
            }); 
 
            var bindingContext = (App.Current.MainPage as MainPage).Schedule.BindingContext; 
 
            if(bindingContext != null && bindingContext is SchedulerViewModel) 
            { 
                (bindingContext as SchedulerViewModel).Meetings = scheduleAppointments; 
            } 
        } 
 
We have prepared a sample for the same, 
Sample link: ScheduleSample 
 
Kindly refer our KB documentation to know about loading DataSource from using WebApi 
 
If the shared information doesn’t meet your requirement kindly modify the sample based on your requirement and revert us back, it will be helpful for us to analyze further and provide you the best solution at the earliest. 
 
Regards, 
Karthik Raja A 


George
Replied On February 4, 2020 09:37 PM UTC

Hi,
Thank you for your time.
Tried to implement your code but its not working.
This line is not working

var bindingContext = (App.Current.MainPage as MainPage).Schedule.BindingContext; 
Please consider that the scheduler is on a child page of a tabbed page 
and i am trying to get the bindingContext from another class.
I added this line in SignalRService.cs
var bindingContext = (App.Current.MainPage as SchedulerPage).Schedule.BindingContext;
but i cant get the bindingContext value.No exception thrown but not responding also.
Thank you


Karthikraja Arumugam [Syncfusion]
Replied On February 5, 2020 08:36 AM UTC

Hi George, 
 
Thank you for the update. 
 
Since Schedule and SignalR service pages are in different tabs of Tapped page, we cannot get the other page instance, here we have to use the MVVM pattern. Set the same binding context for Schedule and SignalR page inside Tapped page, for which set binding context for TappedPage and refer same instance of binding context to both Schedule and SignalR page. So if you change the value of binding context in one page it will reflect on another page also. Here we have to use the same instance of binding context for both the pages. 
 
Please refer the following code example for the same, 
<TabbedPage.BindingContext> 
        <schedulesample:SchedulerViewModel x:Name="scheduleViewModel"/> 
    </TabbedPage.BindingContext> 
     
    <NavigationPage Title="Schedule"> 
        <x:Arguments> 
            <schedulesample:MainPage BindingContext="{x:Reference scheduleViewModel}"/> 
        </x:Arguments> 
    </NavigationPage> 
    <NavigationPage Title="SignalR Page"> 
        <x:Arguments> 
            <schedulesample:ButtonPage BindingContext="{x:Reference scheduleViewModel}"/> 
        </x:Arguments> 
    </NavigationPage> 
 
We have prepared a sample for the same, 
Sample link: ScheduleSample 
 
Note: ViewModel class should inherit INotifyPropertyChanged to notify the property changes to another page. 
 
We hope this helps you, please let us know you have any concerns. 
 
Regards, 
Karthik Raja A 


Karthikraja Arumugam [Syncfusion]
Replied On February 5, 2020 08:36 AM UTC

Hi George, 
 
Thank you for the update. 
 
Since Schedule and SignalR service pages are in different tabs of Tapped page, we cannot get the other page instance, here we have to use the MVVM pattern. Set the same binding context for Schedule and SignalR page inside Tapped page, for which set binding context for TappedPage and refer same instance of binding context to both Schedule and SignalR page. So if you change the value of binding context in one page it will reflect on another page also. Here we have to use the same instance of binding context for both the pages. 
 
Please refer the following code example for the same, 
<TabbedPage.BindingContext> 
        <schedulesample:SchedulerViewModel x:Name="scheduleViewModel"/> 
    </TabbedPage.BindingContext> 
     
    <NavigationPage Title="Schedule"> 
        <x:Arguments> 
            <schedulesample:MainPage BindingContext="{x:Reference scheduleViewModel}"/> 
        </x:Arguments> 
    </NavigationPage> 
    <NavigationPage Title="SignalR Page"> 
        <x:Arguments> 
            <schedulesample:ButtonPage BindingContext="{x:Reference scheduleViewModel}"/> 
        </x:Arguments> 
    </NavigationPage> 
 
We have prepared a sample for the same, 
Sample link: ScheduleSample 
 
Note: ViewModel class should inherit INotifyPropertyChanged to notify the property changes to another page. 
 
We hope this helps you, please let us know you have any concerns. 
 
Regards, 
Karthik Raja A 


George
Replied On February 5, 2020 01:28 PM UTC

Hi,Thank you for your time.
SignalRService.cs is a Service.
Its not a Child Page of the Tabbed Page.
Do i have to modify the sample code ?
Thank you

UPDATE
Cannot figure out how to add bindingContext to a service.
Its not available.

Karthikraja Arumugam [Syncfusion]
Replied On February 6, 2020 01:17 PM UTC

Hi George, 
 
Thank you for the update. 
 
Based on the shared information we suspect that you are using Schedule in one tabbed page and in the second tabbed page SignalR service is used. As we have mentioned in our previous updates, your requirement can be achieved by changing value of binding context and set same binding context for both the tapped pages. Since the SignalR service is not a direct child of tabbed page, as mentioned in our first update, get binding context of the current MainPage and change the value of it, since both main pages having the same binding context you can access it from both the tabs. 
 
Please refer the following code example for the same, 
//Tab page 
<NavigationPage Title="Schedule"> 
        <x:Arguments> 
            <schedulesample:MainPage BindingContext="{x:Reference scheduleViewModel}"/> 
        </x:Arguments> 
    </NavigationPage> 
    <NavigationPage Title="SignalR Page"> 
        <x:Arguments> 
            <schedulesample:ButtonPage BindingContext="{x:Reference scheduleViewModel}"/> 
        </x:Arguments> 
    </NavigationPage> 
 
//SignalR page 
private void Button_Clicked(object sender, EventArgs e) 
            var bindingContext = App.Current.MainPage.BindingContext; 
 
            if (bindingContext != null && bindingContext is SchedulerViewModel) 
           
                (bindingContext as SchedulerViewModel).Meetings = scheduleAppointments; 
           
 
 
We have prepared a sample for the same, 
Sample link: ScheduleSample 
 
If the shared information doesn’t meet your requirement kindly modify the sample and revert us, it will be helpful for us to analyze further and provide you the best solution at the earliest. 
 
Regards, 
Karthik Raja A 


George
Replied On February 6, 2020 01:55 PM UTC

No.Thats not the case.
I have a Tabbed Page.
This Tabed Page has two Child Pages. Page1 and Page2.
Page1 has the scheduler.
Page2 has some other controls.
Now I have a Service.Its named SignalRServices.cs.
 public class SignalRServices : ISignalRServices
    {}
Its not a page.Its a service class.
I can not pass the  bindingContext as argument on Navigation  as you suggest 
because SignalRServices.cs is not a navigation page.
What i try to do is
when a certain SignalR message is received by the app,the scheduler 
should be refreshed.(GetNewDataFromServer())
I hope you can help me out here.
Thank you



Karthikraja Arumugam [Syncfusion]
Replied On February 7, 2020 06:01 AM UTC

Hi George, 
 
Thank you for the update. 
 
As we have mentioned in our previous you can get the BindingContext of current page and change DataSource. Please check you have bind the appointments from binding context class, if you directly set appointments collection it will not work.  
 
If the suggested solution doesn’t meet your requirement we can set up a web meeting today at 11 AM Greece Time ( 9 AM UTC). Would you please let us know of your availability for the web meeting. 
 
Regards, 
Karthik Raja A 


George
Replied On February 7, 2020 12:16 PM UTC

Hi,
Thank you for making such an effort helping me out.
Sorry for not responding earlier regarding the webmeeting,but i was not at the office
and i missed your message.
We can either do the weebmeeting today ,any time you want or
we can schedule it for Monday,if its ok with you.
Please let me know the details  about how we are going to do this.
Teamviewer or skype would be great.

Thank you
George

Indumathi Ravichandran [Syncfusion]
Replied On February 10, 2020 08:55 AM UTC

Hi George, 
 
We have created a new incident under your Direct trac account and share the meeting details. We suggest you to follow up with the incident for further updates. Please log in using the below link. 
 
 
Regards, 
Indumathi R 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon