Quantcast
Channel: Telerik Blogs | .NET
Viewing all articles
Browse latest Browse all 1954

Using the Multiple Selection of the RadCalendar control for Silverlight and WPF with MVVM

$
0
0

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:

 

Get Microsoft Silverlight

 

And the code of the main page is as follows:

<UserControlx:Class="CalendarAndViewModel.MainPage"
    xmlns:local="clr-namespace:CalendarAndViewModel"
    mc:Ignorable="d"
    d:DesignHeight="300"d:DesignWidth="400">
    <UserControl.DataContext>
        <local:SampleViewModel/>
    </UserControl.DataContext>
 
    <Gridx:Name="LayoutRoot"Background="White">
        <Grid.RowDefinitions>
            <RowDefinitionHeight="25"/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
         
        <StackPanelOrientation="Horizontal"Grid.Row="0">
            <ButtonContent="Select many"Click="OnSelectManyClick"/>
            <ButtonContent="Deselect all"Click="OnDeselectAllClick"/>
        </StackPanel>
         
        <telerik:RadCalendarGrid.Row="1"
                             SelectionMode="Extended"
                             local:CalendarExtensions.TrackCalendarSelectedDates="True"
                             local:CalendarExtensions.SelectedDates="{Binding SelectedDates, Mode=TwoWay}"/>
 
        <ListBoxGrid.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.


Viewing all articles
Browse latest Browse all 1954

Trending Articles