0

编程新手,需要一点帮助。我有一个用于 Outlook 加载项的 WPF 用户控件,一切都很顺利,直到我在 celleditingtemplate 列中尝试了一个带有日期选择器的数据网格,但 celltemplatecolumn 只是有一个文本块。这个想法是将文本块绑定到数据源(工作正常),当用户编辑列时,日期选择器显示并且用户可以选择一个日期。我根本无法弄清楚如何将选定日期中的值发送到文本块,我完全束手无策。下面是数据网格及其绑定,带有以下字段的简单 SQL 表:[Project]、[Deadline]、[DaystoDeadline]、[Responibility]、[ProcessCount]、[TasksCompleted]、[TasksRemaining]。任何帮助将不胜感激。

            <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>
4

1 回答 1

0

我将首先删除 ( ) 中的控件名称并从: ( DataTemplate)中x:Name="DeadlineTxt" x:Name="DeadlineDatePicker"删除StringFormatSelectedDateSelectedDate="{Binding Deadline}"

            <DataGridTemplateColumn Header="Deadline">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Deadline, StringFormat='yyyy/MM/dd'}" FontFamily="Verdana" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <DatePicker SelectedDate="{Binding Deadline}" FontFamily="Verdana" >
                            <DatePicker.CalendarStyle>
                                <Style TargetType="Calendar">
                                    <Setter Property="DisplayMode" Value="Month"/>
                                </Style>
                            </DatePicker.CalendarStyle>
                        </DatePicker>
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>
于 2012-07-26T13:56:05.780 回答