如何在DataGrid WPF中制作日历列 [英] How I can make a calender column in DataGrid WPF
本文介绍了如何在DataGrid WPF中制作日历列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在WPF的DataGrid中将显示时间和日期的特定列设置为日历列
how I can set a particular column as calender column which displays both time and date , in DataGrid of WPF
推荐答案
好,您必须添加一个模板字段在此字段中,您可以添加任何想要的控件,例如:
ok man you have to add a template field and inside this field you can add any control you want ex:
<asp:TemplateField HeaderText="Date" >
<ItemTemplate>
<--Add here a date time controll or calendar--;" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
您可以使用您可以设置列的
DataTemplate
,如下所示:You can set the
DataTemplate
of your column, like the following:<DataGrid ItemsSource="{Binding MyObjectsProperty}"> <DataGrid.Columns> <DataGridTemplateColumn Header="My calendar column"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <!-- Replace following DataTemplate with a calendar DataTemplate --> <Border BorderBrush="Blue" Background="LightBlue" BorderThickness="2" Padding="10"> <TextBlock Text="{Binding MyDateProperty}" /> </Border> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid>
这篇关于如何在DataGrid WPF中制作日历列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文