I use a RadDatePicker inside a DataTemplate and assign it to the CellEditTemplate of a column of a RadGridView. When I do this, the RadDatePicker does not pick up the value of the current cell (or of the datasource collection behind it), but it is initialized to nothing. So I tried to set the initial value of the datepicker programmatically. You see my attempt in the code below. But it does not work. Can you give me a way to set an initial value in the RadDatePicker control.
XAML
=====
<Grid.Resources>
<DataTemplate x:Key="UIDatePicker">
<input:RadDatePicker x:Name="UIRadDatePicker" SelectionChanged="UIRadDatePicker_SelectionChanged" Loaded="UIRadDatePicker_Loaded"/>
</DataTemplate>
</Grid.Resources>
Code
====
// I have the value in rowrec.fodWert and would like to initalize the DatePicker to this value.
private void UIRadGridFormular_CurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs evt)
{
GridViewCell newCell = evt.NewCell;
RecFormulare rowrec = (RecFormulare)rowItem.DataContext;
DataTemplate templa = LayoutRoot.Resources["UIDatePicker"] as DataTemplate;
((GridViewDataColumn)this.UIRadGridFormular.Columns["UIWert"]).CellEditTemplate = templa;
RadDatePicker rdp = LayoutRoot.Resources["UIRadDatePicker"] as RadDatePicker;
DateTime dt;
bool ok = DateTime.TryParse(rowrec.fodWert, out dt);
if (ok)
{
if (rdp != null)
{
rdp.DisplayDate = dt; // Does not work
}
newCell.Value = dt; // Does not work
}