我的日期在XAML中有以下数据网格列。我需要以“MM / dd / yyyy”格式格式化它。
<sdk:DataGridTextColumn Width="Auto" Binding="{Binding MyDate, StringFormat='MM/dd/yyyy'}" Header="Date" />
如何在C#中重现字符串格式化部分?我想在代码中向我的Datagrid添加新列。
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Date";
textColumn.Binding = new Binding("MyDate");
textColumn.CanUserReorder = true;
//????
this.MyDataGrid.Columns.Add(textColumn);
答案 0 :(得分:1)
这样的事情怎么样?
var binding = new Binding("MyDate");
binding.StringFormat = "MM/dd/yyyy";
textColumn.Binding = binding;
答案 1 :(得分:1)
怎么样?
textColumn.Binding = new Binding("MyDate") {StringFormat = "MM/dd/yyyy"};