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:
... and the .cs looks like:
Thanks for any help!
Simon.
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"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
Window.Resources
>
<
DataTemplate
x:Key
=
"ViewTemplate"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"{Binding Path=Title}"
/>
<
TextBlock
Text
=
"{Binding Path=Date}"
/>
</
StackPanel
>
</
DataTemplate
>
<
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}"
/>
</
StackPanel
>
</
DataTemplate
>
<
Style
x:Key
=
"ContainerStyle"
TargetType
=
"{x:Type ListBoxItem}"
>
<
Setter
Property
=
"ContentTemplate"
Value
=
"{StaticResource ViewTemplate}"
/>
<
Style.Triggers
>
<
Trigger
Property
=
"IsSelected"
Value
=
"True"
>
<
Setter
Property
=
"ContentTemplate"
Value
=
"{StaticResource EditTemplate}"
/>
</
Trigger
>
</
Style.Triggers
>
</
Style
>
</
Window.Resources
>
<
Grid
>
<
ListBox
x:Name
=
"MyListBox"
IsSynchronizedWithCurrentItem
=
"True"
ItemContainerStyle
=
"{StaticResource ContainerStyle}"
/>
</
Grid
>
</
Window
>
... 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()
{
InitializeComponent();
// 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
{
// Set a breakpoint here once the form is displayed,
// clicking a listbox row will immediatley break here
_date = value;
}
}
}
}
Thanks for any help!
Simon.