Unable to bind View
I am trying to bind the View property to ScheduleView in my view model but it is ignored and defaults to Day view. This is in my view:
<scheduler:SfScheduler x:Name="Scheduler" Grid.Row="2"
View="{Binding ScheduleView}"
FirstDayOfWeek="Sunday"
Tapped="Scheduler_Tapped"
SelectedCellBackground="SlateBlue"
AppointmentsSource="{Binding AgentAssignments}"
ShowWeekNumber="False"
VerticalOptions="FillAndExpand"
AllowedViews="Day,Week,Month,Agenda">
This is in my code behind:
public AgentSchedulePage(SchedulerViewModel viewModel)
{
BindingContext = viewModel;
InitializeComponent();
}
and this is in my view model:
[ObservableProperty]
private string _scheduleView = "Month";
When I run it displays in Day view instead of Month view.
My intent is to save the user's view preference and default it to that the next time they run the app.
Thanks
Hi Phill,
Thank you for reaching out. Based on the shared information we have checked your query. In the provided code snippet, you are utilizing AllowedViews. In the current implementation, the scheduler's view is set to the first view in the allowed view list upon initial loading. However, you can definitely change the view at runtime to fit your needs.
If you have any additional questions or require further assistance, please feel free to let us know. We're here to assist you.
Regards,
Vidyalakshmi M.
Thanks for your reply. I tried changing the order of the allowed view list, it has no effect. If I understand your response, binding is not supported for the view property. Is that correct?
Hi Phill,
After examining the code snippets, you provided, we noticed that the `_scheduleView` property, which you attempted to bind to the `View` property of the Scheduler, is of type string. However, the `View` property in the Scheduler is of type `ScheduleView`, which is an enum. Due to this type mismatch, the binding of the `_scheduleView` property did not function as expected. To address this issue, we suggest changing the type of the `_scheduleView` property in your view model from string to `ScheduleView`. Please see the following code snippet for your reference:
SchedulerViewModel class
|
private SchedulerView scheduleView = SchedulerView.Month;
public SchedulerView ScheduleView { get { return scheduleView; } set { scheduleView = value; } }
|
After making this change, we verified that the binding works correctly. We have also created a simple sample demonstrating this modification and attached it for your reference. Please check the sample and let us know if it resolves the issue.
Regards,
Vidyalakshmi M.
Attachment: GettingStarted_3139d6cb.zip
- 3 Replies
- 2 Participants
-
PH Phill
- Mar 14, 2024 05:00 PM UTC
- Mar 20, 2024 03:17 PM UTC