Telerik blogs

Developing and supporting MVVM applications is easy and effective. That's why we want to create MVVM applications that follow this pattern. Sometimes the controls we use have some limitations. For example, list properties, which are read-only and do not allow us to create an appropriate binding to our view-models. It is normal for properties of list type to be read-only, because this is considered a good practice, but it becomes a problem for the MVVM pattern. In the ItemsControl this problem is solved with two properties - Items and ItemsSource. This blog post is about an example that demonstrates how to create an additional property for the SelectedDates property of the RadCalendar control.

Here is the demo application:

 

 

And the code of the main page is as follows:

<UserControl x:Class="CalendarAndViewModel.MainPage"
    xmlns:local="clr-namespace:CalendarAndViewModel"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.DataContext>
        <local:SampleViewModel />
    </UserControl.DataContext>
 
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="25" />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
         
        <StackPanel Orientation="Horizontal" Grid.Row="0">
            <Button Content="Select many" Click="OnSelectManyClick" />
            <Button Content="Deselect all" Click="OnDeselectAllClick" />
        </StackPanel>
         
        <telerik:RadCalendar Grid.Row="1"
                             SelectionMode="Extended"
                             local:CalendarExtensions.TrackCalendarSelectedDates="True"
                             local:CalendarExtensions.SelectedDates="{Binding SelectedDates, Mode=TwoWay}" />
 
        <ListBox Grid.Row="2" ItemsSource="{Binding SelectedDates}">
 
        </ListBox>
    </Grid>
</UserControl>

 

 

The details of the implementation process are not a subject of this article, so I will just share the project here. If interested, you can download it from here.


About the Author

Miroslav Nedyalkov

is a XAML enthusiast. Speaker at various local user groups and events. Miroslav is passionate about cutting edge technologies and likes to share his knowlage with others. You can follow him on Twitter at @miro_nedyalkov.

Comments

Comments are disabled in preview mode.