New to programming and need a little assistance. I have a WPF usercontrol used for an Outlook Add-in and everything was going swimmingly until I tried a datagrid with a datepicker in the celleditingtemplate column but the celltemplatecolumn simply has a textblock. The idea is to have the textblock bound to the datasource (which is working fine) and when the user edits the column, the datepicker shows and the user can select a date. I simply cannot figure out how to send the value from the selecteddate to the textblock and I’m completely at my wits end. Below is the datagrid with its bindings, simple SQL table with the following fields, [Project],[Deadline],[DaystoDeadline],[Responibility],[ProcessCount],[TasksCompleted],[TasksRemaining]. Any assistance would be greatly appreciated.
<Grid>
<DataGrid AutoGenerateColumns="False" HorizontalAlignment="Left" Margin="6,0,0,0" Name="ProjectsGrid" ScrollViewer.CanContentScroll="True" VerticalAlignment="Top" VerticalScrollBarVisibility="Auto" ItemsSource="{Binding}" CanUserAddRows="False" CanUserDeleteRows="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Commands">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="Select_Button" Content="Select" Name="SelectButton" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Project}" Header="Project" IsReadOnly="True" FontFamily="Verdana" />
<DataGridTemplateColumn Header="Deadline">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Deadline, StringFormat='yyyy/MM/dd'}" FontFamily="Verdana" x:Name="DeadlineTxt" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Deadline, StringFormat='yyyy/MM/dd'}" FontFamily="Verdana" x:Name="DeadlineDatePicker">
<DatePicker.CalendarStyle>
<Style TargetType="Calendar">
<Setter Property="DisplayMode" Value="Month"/>
</Style>
</DatePicker.CalendarStyle>
</DatePicker>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding DaystoDeadline}" Header="Days to Deadline" IsReadOnly="True" FontFamily="Verdana" />
<DataGridTextColumn Binding="{Binding Responsibility}" Header="Responsibility" IsReadOnly="True" FontFamily="Verdana" />
<DataGridTextColumn Binding="{Binding Processes}" Header="Processes" IsReadOnly="True" FontFamily="Verdana" />
<DataGridTextColumn Binding="{Binding Completed}" Header="Completed" IsReadOnly="True" FontFamily="Verdana" />
<DataGridTextColumn Binding="{Binding Remaining}" Header="Remaining" IsReadOnly="True" FontFamily="Verdana" />
</DataGrid.Columns>
</DataGrid>
I would start by taking off the names of the controls in the
DataTemplate(x:Name="DeadlineTxt"x:Name="DeadlineDatePicker") and remove theStringFormatfrom theSelectedDate: (SelectedDate="{Binding Deadline}")