RadDatePicker in a DataTemplate

2 posts, 0 answers
  1. Simon
    Simon avatar
    1 posts
    Member since:
    Aug 2010

    Posted 21 Oct 2010 Link to this post

    I have a listbox that shows dates, when a user clicks on a specific date I want it to become editable. So when I click on the listbox item, a trigger switches its datatemplate from a template containing a textblock to a template containing a RadDatePicker.

    When this occurs, the RadDatePicker immediatley updates the binding source with the value.  Why is this?  The WPF Toolkit date picker does not do this, but I'd have to use the RadDatePicker.

    Because I am using entity framework self tracking entities, this immediatley marks the entity I've bound to as modified.

    Does anyone know a way to stop the RadDatePicker updating the binding source as soon as it appears on a datatemplate?

    I've recreated this problem in a test window.  The XAML looks like this:

    <Window x:Class="RadDatePickerInTemplate.MainWindow"
            Title="MainWindow" Height="350" Width="525">
            <DataTemplate x:Key="ViewTemplate">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Title}" />
                    <TextBlock Text="{Binding Path=Date}" />
            <DataTemplate x:Key="EditTemplate">
                <StackPanel Orientation="Horizontal">
                    <TextBox Text="{Binding Path=Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <telerik:RadDatePicker SelectedDate="{Binding Path=Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            <Style x:Key="ContainerStyle" TargetType="{x:Type ListBoxItem}">
                <Setter Property="ContentTemplate" Value="{StaticResource ViewTemplate}"/>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="ContentTemplate" Value="{StaticResource EditTemplate}"/>
            <ListBox x:Name="MyListBox"
                     ItemContainerStyle="{StaticResource ContainerStyle}" />

    ... and the .cs looks like:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    namespace RadDatePickerInTemplate
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
            public MainWindow()
                // Show a list of Dates
                MyListBox.ItemsSource = new List<ListItem>()
                    new ListItem() { Title = "Test 1", Date = new DateTime(2010, 3, 27) },
                    new ListItem() { Title = "Test 2", Date = new DateTime(2010, 8, 19) },
                    new ListItem() { Title = "Test 3", Date = new DateTime(2010, 2, 3) }
        public class ListItem
            public string Title { get; set; }
            private DateTime _date;
            public DateTime Date
                get { return _date; }
                    // Set a breakpoint here once the form is displayed, 
                    // clicking a listbox row will immediatley break here
                    _date = value;

    Thanks for any help!
  2. Kaloyan
    Kaloyan avatar
    920 posts

    Posted 25 Oct 2010 Link to this post

    Hello Simon,

    Since the Q2.2010 release we have made major changes regarding the Date/Time pickers control. As a result the control has a new property SelectedValue, that must be used as it represent the SelectedDate merged with the SelectedValue. What you have to do is to replace the SelectedDate with SelectedValue property. Sorry for the misleading caused.

    Kind regards,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top