我有一个WPF数据网格,其绑定到类对象,如下所示:
$mysqli=new mysqli("localhost","root","root","123");
$query="select * from test";
$result=$mysqli->query($query);
if ($result) {
if($result->num_rows>0){
while($row =$result->fetch_array() ){
echo ($row[0])."<br>";
echo ($row[1])."<br>";
echo ($row[2])."<br>";
echo ($row[3])."<br>";
echo "<hr>";
}
}
}else {
echo 'failure';
}
$result->free();
$mysqli->close();
该类中的属性非常简单,如下所示:
<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate }" />
当我填充此属性时,我只发送public DateTime OrderDate { get; set; }
(仅限日期,而非时间):
DateTime.Date
不幸的是,这并没有反映在我的WPF数据网格中,因为它显示了日期,但它也将时间(无处不在)显示为.Select(
r =>
new Customer
{
Persona = r.Persona,
CustomerName = r.CustomerName,
Email = r.Email,
Organization = r.Organization,
PhoneNumber = r.PhoneNumber,
Street = r.Street,
Suburb = r.Suburb,
Postcode = r.Postcode,
OrderDate = r.OrderDate.Date
}))
。我应该如何让我的WPF数据网格仅显示日期?
答案 0 :(得分:9)
试试这个
<DataGridTextColumn Header="Order Date" Binding="{Binding OrderDate , StringFormat=d}" />
有关字符串格式here
的更多信息答案 1 :(得分:0)
或者,您也可以在代码中完成此操作:
((DataGridTextColumn)YourGridName.Columns[0]).Binding.StringFormat = "d";
(信用:我从马克·费尔德曼(Mark Feldman)对以下问题的回答中得到了他的信息:Date formatting in WPF datagrid)