DatePicker not updating when in RowDetailsTemplate

Feb 19, 2009 at 9:17 AM

Can any help with below issue

DatePicker  not update value in DataGrid when using a RowDetailsTemplate, textboxes checkbox all seem ok but have problem when selected a date the value is not updated.

Binidng to a object that holds name and date of birth, inside the template you can change the name with no issue but when selected a date or typing a date nothing happens, here is the xaml.


  <my:DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <Border Background="LightBlue" CornerRadius="15" Margin="10">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="100"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0">
                                <Label>Name</Label>
                                <Label>Date Of Birth</Label>
                                <Label>Been Good</Label>
                            </StackPanel>

                            <StackPanel Grid.Column="1">
                                <TextBox Text="{Binding Path=Name}"/>
                                <my:DatePicker SelectedDate="{Binding Path=Dob}" />
                                <CheckBox IsChecked="{Binding Path=BeenGood}"/>
                            </StackPanel>

                        </Grid>
                    </Border>
                </DataTemplate>
            </my:DataGrid.RowDetailsTemplate>

Coordinator
Feb 19, 2009 at 5:24 PM
Hi alexjohnhill,

This sounds like it might be due to a bug in DatePicker where the binding on SelectedDate isn't TwoWay by default.  Try changing the SelectedDate binding to:

SelectedDate="{Binding Path=Dob, Mode=TwoWay}"

Thanks,
Samantha
Coordinator
Feb 19, 2009 at 6:09 PM
This bug will be fixed in the next release.
Feb 20, 2009 at 12:55 AM
Thanks for the responses I was unaware of the default binding mode for the DateTimePicker. However I have tried setting the binding to 2 way in the DataGrid.RowDetailsTemplate and get the same result. What I have noticed is that the selection of a date in the DateTimePicker is being registered as a MouseDown / mouse LeftbuttonDown event on the DataGrid, with no selectedDateChange being fired for the DateTimePicker.

below is simple example xaml with code that when run shows you can edit date in DataGrid Cell ok, but can't edit date in the RowDetailsTemplate

<Window x:Class="WpfApplicationTestRowDetails2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="378" Width="520" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit">
    <Grid>
        <my:DataGrid Margin="33,36,19,14" Name="dataGrid1" AutoGenerateColumns="True">

            <my:DataGrid.Columns>
                <my:DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"/>
                <my:DataGridTemplateColumn Header="Date Of Birth">
                    <my:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <my:DatePicker SelectedDate="{Binding Path=Dob,Mode=TwoWay}"/>
                        </DataTemplate>
                    </my:DataGridTemplateColumn.CellTemplate>
                </my:DataGridTemplateColumn>
            </my:DataGrid.Columns>

            <my:DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <Border Background="LightBlue" CornerRadius="15" Margin="10">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="100"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0">
                                <Label>Name</Label>
                                <Label>Date Of Birth</Label>
                            </StackPanel>

                            <StackPanel Grid.Column="1">
                                <TextBox Text="{Binding Path=Name}"/>
                                <my:DatePicker SelectedDate="{Binding Path=Dob,Mode=TwoWay}"/>
                            </StackPanel>
                        </Grid>
                    </Border>
                </DataTemplate>
            </my:DataGrid.RowDetailsTemplate>
        </my:DataGrid>
    </Grid>
</Window>



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;
using Microsoft.Windows.Controls;

namespace WpfApplicationTestRowDetails2
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        List<Tester> tests;

        public Window1()
        {

            tests = new List<Tester>();

            tests.Add(new Tester("Alex Hill", DateTime.Now));
            tests.Add(new Tester("Jane Hill", new DateTime(1971, 7, 20)));
            tests.Add(new Tester("Lewis Hill", new DateTime(2005, 10, 8)));
            tests.Add(new Tester("Alicia Hill", new DateTime(2007, 9, 4)));

            InitializeComponent();

            dataGrid1.ItemsSource = tests;
        }
    }

    public class Tester
    {
        private string name;
        private DateTime dob;

        public Tester(string name, DateTime dob)
        {
            this.name = name;
            this.dob = dob;
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public DateTime Dob
        {
            get { return dob; }
            set { dob = value; }
        }
    }
}


Coordinator
Feb 20, 2009 at 5:11 PM
Hi alexjohnhill,

Ah, I see.  This sounds like it is due to a known bug in DataGrid, where when you click on any Popups in row details, the click goes through to the DataGrid and doesn't register on the Popup.  This will be fixed in our next release also.  In the meantime, I don't believe there's a workaround besides using a different control in your RowDetailsTemplate which doesn't have a popup.

Thanks,
Samantha
Feb 23, 2009 at 8:47 AM

Samantha,

Do you know when the next release is planned ?
Coordinator
Feb 23, 2009 at 5:34 PM
We've got one planned (with DataGrid and DatePicker bug fixes) within the next few weeks, but I don't have an exact date yet.  I think at the latest it will be a week or two after we release .NET 4.0 Beta 1, but we're hoping to get it out before then.