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. Image for the cookie policy date

Binding Calendar to DataTemplate

I'm currently using the samples for WinRT controls and trying prove out some concepts on a project of mine.  I want to do something similar to the AppointmentsDemo and can't seem to get my DataContext to bind to the DataTemplate.  I'm using the MVVM pattern and can bind everything else.  Even when I mimic the examples exactly I get a null value in the ConverterParameter for the CellTemplate.

        <DataTemplate x:Key="CellTemplate">
            <Grid>
                <TextBlock Text="{Binding Converter={StaticResource CellConverter}, ConverterParameter={Binding TempData}}"
                               VerticalAlignment="Top" HorizontalAlignment="Right"
                               Margin="3" FontSize="8" TextWrapping="Wrap" />
                <TextBlock Text="{Binding Day}"
                               VerticalAlignment="Bottom"
                               Margin="3" />
            </Grid>
        </DataTemplate>

4 Replies

KL Karthikeyan L Syncfusion Team February 25, 2013 11:36 AM UTC

Hi Michael,

We cannot bind the member to the ConvertParameter since it is not a dependency property. We have prepared a sample based on your requirement by passing the collection as resource to ConvertParameter. We have attached the sample for your reference.

Could you please check the attached sample and let us know whether the sample meet the requirement.

[Sample link]: http://www.syncfusion.com/downloads/Support/DirectTrac/General/Calender_Demo-1491579611.zip

Please let us know if you have any concerns.

Regards,
Karthikeyan L.


MS Michael Sherburne March 9, 2013 05:48 PM UTC

That's essentially what I had to do.  I was getting hung up on trying to pull data from my ViewModel.  For anyone who is curious here is my code sample.

        <!-- Data Resources -->
        <Data:TaskItemData x:Key="TaskItemData" />

        <DataTemplate x:Key="CellTemplate">
            <Grid>
                <TextBlock Text="{Binding Date, Converter={StaticResource CellConverter}, ConverterParameter={StaticResource TaskItemData}}"
                       VerticalAlignment="Top" HorizontalAlignment="Right"
                       Margin="3" FontSize="5" TextWrapping="Wrap"/>
                <TextBlock Text="{Binding Day}"
                       VerticalAlignment="Bottom"
                       Margin="3"/>
            </Grid>
    </DataTemplate>

        public TaskItemData()
        {
            ViewModel.ViewModelLocator locator = App.Current.Resources["Locator"] as ViewModel.ViewModelLocator;

            if (locator != null)
            {
                List<TaskViewModel> tasks = locator.Main.Tasks;
                this.AddRange(tasks);
            }           
        }


KL Karthikeyan L Syncfusion Team March 11, 2013 01:26 PM UTC

Hi Michael,

Based on your code snippet, we have prepared a sample and we have attached the sample for your reference. Please check the sample and let us know the sample meet your requirement, otherwise please provide some information regarding the problem you are facing.

[Sample link]: http://www.syncfusion.com/downloads/Support/DirectTrac/General/Calender_Demo1014616385.zip

Please let us know if you have any queries.

Regards,
Karthikeyan.



IP Imran Prasla May 28, 2014 02:24 PM UTC

My case is somewhat similar to the ones above. What I am trying to achieve is there is a service/api that I call in order to get what events fall on what day and based on that I bind the data to the calendar. The above scenarios doesn't work because the calendar gets initialized before the service request is completed. Therefore, it is always blank events. My viewmodel calls the service and viewmodel binds to any control via the code behind file. Let me know if there is a better way to achieve this problem.

Loader.
Up arrow icon