1

I would like to add a click event, which sends information about the day, on the dayitem in the CalenderView in UWP. I'm having a hard time figuring out how.

[CalenderView[1] I've already tried following, but it does not work and I can imagine that there's better ways to do it.

      private async void KalenderView_DoubleTappedAsync(object sender, DoubleTappedRoutedEventArgs e)
    {
        Viewmodel.Calendar_ViewModel calender_Viewmodel = new Viewmodel.Calendar_ViewModel();

          if ( KalenderView.SelectedDates != null )
        {
            await calender_Viewmodel.OpenNewWindowAsync();

        } 
        else
        { 
        }
    }
}

and the XML:

<Grid>
    <CalendarView 
        x:Name="KalenderView" 
        DoubleTapped="KalenderView_DoubleTappedAsync" 
        CalendarViewDayItemChanging="CalendarView_CalendarViewDayItemChanging"  HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" Height="526" Width="936"
       SelectionMode="Single"
        DisplayMode="Month"/>
</Grid>
Mohammad Saad
  • 127
  • 1
  • 11
  • Please share a code snippet of what you have tried, you are likely to get a response. The question is having very low effort. Going through documentation should help you answer this - https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.CalendarView#Windows_UI_Xaml_Controls_CalendarView_SelectedDatesChanged – Carbine Sep 04 '18 at 12:40

1 Answers1

0

you can use SelectedDatesChanged event for this purpose it will be invoked whenever you change the date from the calender in any way and within this event you can see the new date of the calender which is currently selected and access, just the dayitem or any other properties on the calenderdayitem.

if you want to specifically add an event to when a day item can be clicked it can be a bit complicated, as you will have to create a control ( refer : Templated Control vs Custom Control in UWP. No clear answer found online ) but I suggest dont do that unless you have no other option and you know what you are doing.

Muhammad Touseef
  • 4,357
  • 4
  • 31
  • 75