0
votes

Right now i have a calendar which is : https://github.com/lubiepomaranczki/XamForms.Controls.Calendar, if i click on the day and there's data for this day, it lists the data for this day like that :

[15 july clicked1

My problem is that i don't know how to go from ViewModel to code behind to tell him to switch the IsVisible value to true. I never faced this problem, usually we just send data from the UI to ViewModel.

Thanks for help.

If i click a date with no value, i want to make this stacklayout which is from CalendarPage.xaml visible:

        <StackLayout IsVisible="false" x:Name="PlusIconStackLayout">
            <ImageButton Source="iconplus.png"  HeightRequest="30" WidthRequest="30"></ImageButton>
        </StackLayout>

In my CalendarPageViewModel.cs i already have a command that checks if if the TasksGroup exist or not and load the data if it does.

public ICommand DateChosen => new Command((obj) =>
{
    var dateChosen = obj as DateTime?;

    if (dateChosen != null)
    {

        tasksGroup = App.Database.GetTaskGroupByDate(dateChosen.Value).GetAwaiter().GetResult();
        if (tasksGroup != null)
        {

            var data = App.Database.GetTaskByGroupId(TasksGroup.ID).GetAwaiter().GetResult();
            TasksGroup = tasksGroup;
            TasksGroup.Taches = data;
            TasksGroup.ExpositionResult = Helper.CalculateExposition(TasksGroup);
            ExpositionResult = TasksGroup.ExpositionResult;

            Tasks = new ObservableCollection<Tasks>(data);
            TasksGroup.Taches.ForEach(x =>
            {
                TaskDBA = x.TaskDBA;
                TaskDuration = x.TaskDuration;
                TaskDescription = x.TaskDescription;
            });

        }
        else
        {
            Tasks = null;
            TasksGroup = null;
            ExpositionResult = null;
        }
    }

});

In the CalendarPage.xaml.cs i have a DateClicked function that i could use but i am unsure how to link it based on VewModel result

public void DateClicked(object sender, DateTime e)
{
    PlusIconStackLayout.IsVisible = true;

}
1
why don't you just bind IsVisible to a property on your VM?Jason
@Jason Could you post a snippet to give me an idea because i am not sure that i am following ( i'm really visual haha)codetime

1 Answers

0
votes

i don't know how to go from ViewModel to code behind to tell him to switch the IsVisible value to true.

You don't need to do this. If you want to control the value of a UI property from the ViewModel, use data binding to do it. You don't need to do anything in the code-behind

<StackLayout IsVisible="{Binding SomeBoolProperty}" x:Name="PlusIconStackLayout">
  <ImageButton Source="iconplus.png"  HeightRequest="30" WidthRequest="30"></ImageButton>
</StackLayout>

then in your VM, create a property (be sure to use INotifyPropertyChanged)

public bool SomeBoolProperty { ... }

and whenever you need to toggle the visibility of that UI, just set the appropriate value of the property