& lt數據網格。列& gt& lt" />
前端:
& lt網格& gt
& ltDataGrid autogenerate columns = " False " Name = " DataGrid 1 " >
& lt數據網格。列& gt
& ltdatagrid text column Binding = " { Binding Key } "/& gt;
& ltdatagrid template column Header = " time " >
& ltDataGridTemplateColumn。CellTemplate & gt
& lt數據模板& gt
& lttext block MouseDown = " txt date _ MouseDown " Name = " txt date "/& gt;
& lt/data template & gt;
& lt/DataGridTemplateColumn。CellTemplate & gt
& lt/datagrid template column & gt;
& lt/DataGrid。列& gt
& lt/DataGrid & gt;
& lt/Grid & gt;
後臺:
公共主窗口()
{
initialize component();
字典& ltint,string & gtdic =新詞典& ltint,string & gt
{
{1," a"},
{2," b"},
{3," c"},
{4," d"},
{5," e"}
};
dataGrid1ItemsSource = dic
}
private void txtdate_MouseDown(對象發送方,MouseButtonEventArgs e)
{
TextBlock tb =發件人as TextBlock
肺結核。Text =日期時間。now . toshortimestring();
}