<data:DataGrid x:Name="dgList" Grid.Row="1" AutoGenerateColumns="True" FrozenColumnCount="5" AutoGeneratingColumn="dgList_AutoGeneratingColumn">
<data:DataGrid.Columns>
<data:DataGridCheckBoxColumn Header="选择" Binding="{Binding IsSelected,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="导入类型" Binding="{Binding IMPORTTYPE,Mode=TwoWay}" Visibility="Collapsed" IsReadOnly="True"/>
<data:DataGridTextColumn Header="监测类型" Binding="{Binding TYPE,Mode=TwoWay}" Visibility="Collapsed" IsReadOnly="True"/>
<data:DataGridTextColumn Header="监测点名称A" Binding="{Binding PlaceA, Mode=TwoWay}" IsReadOnly="True" />
<data:DataGridTextColumn Header="监测点名称B" Binding="{Binding PlaceB }" IsReadOnly="True"/>
<data:DataGridTextColumn Header="位置" Binding="{Binding POSITION, Mode=TwoWay}" IsReadOnly="True" />
<data:DataGridTextColumn Header="横向位置" Binding="{Binding PositionHorizontal, Mode=TwoWay}" IsReadOnly="True" />
<data:DataGridTextColumn Header="纵向位置" Binding="{Binding PositionVertical, Mode=TwoWay}" IsReadOnly="True" />
<data:DataGridTextColumn Header="监测日期" Binding="{Binding InspectDate, Mode=TwoWay}" IsReadOnly="True" /></data:DataGrid.Columns>
</data:DataGrid>
后台代码 用dgList_AutoGeneratingColumn事件来处理 日期显示不行
private void dgList_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
string header = e.Column.Header.ToString();
//格式化DataGrid中日期格式(原来显示的日期格式非常长,有没必要的信息)
if (header.Contains("日期") || header.Contains("时间") || header.Contains("InspectDate"))
{
if (e.Column is DataGridTextColumn)
{
DataGridTextColumn col = e.Column as DataGridTextColumn;
col.Binding.Converter = new ValueConverter.DateConvertor() { FormartString = "yyyy-MM-dd" };
}
}
//e.Column.Header = System.Xml.XmlConvert.DecodeName(header);
}
XML里的日期数据得到的是2008/1/1为什么绑定到datagrid上面就改变了
怎么解决啊
datagrid使用的GMT格式,可以自定义一个Convert实现自己需要的格式