在DataGrid格式的值 [英] Format values in a Datagrid
本文介绍了在DataGrid格式的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法来格式化绑定到DataGrid的价值观?例如,我有以下几点:
<数据网格的AutoGenerateColumns =FALSEHEIGHT =487的HorizontalAlignment =左保证金=12,12,0,0NAME =dgTransactionLogVerticalAlignment =评出的WIDTH =404>
< DataGrid.Columns>
< DataGridTextColumn绑定={绑定路径=日期}标题=日期/>
< DataGridTextColumn绑定={绑定路径= Payee1.Name}标题=到/从/>
< DataGridTextColumn绑定={绑定路径=金额}标题=金额/>
< /DataGrid.Columns>
< / DataGrid的>
我想日期列只是日期(没有时间)和金额列是货币格式。以下是我填充DataGrid:
VAR交易= TransactionManager.GetTransactions();
dgTransactionLog.ItemsSource =交易;
解决方案
使用的StringFormat
属性:
< DataGridTextColumn绑定={绑定路径=日期,的StringFormat = D}标题= 日期/>
< DataGridTextColumn绑定={绑定路径=金额,的StringFormat = C}标题=金额/>
Is there any way to format the values that are bound to a datagrid? For example I have the following:
<DataGrid AutoGenerateColumns="False" Height="487" HorizontalAlignment="Left" Margin="12,12,0,0" Name="dgTransactionLog" VerticalAlignment="Top" Width="404">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Date}" Header="Date" />
<DataGridTextColumn Binding="{Binding Path=Payee1.Name}" Header="To/From" />
<DataGridTextColumn Binding="{Binding Path=Amount}" Header="Amount" />
</DataGrid.Columns>
</DataGrid>
I'd like the Date column to be just date (not time) and the Amount column to be currency format. Here's how I populate the datagrid:
var transactions = TransactionManager.GetTransactions();
dgTransactionLog.ItemsSource = transactions;
解决方案
Use the StringFormat
property:
<DataGridTextColumn Binding="{Binding Path=Date, StringFormat=d}" Header="Date" />
<DataGridTextColumn Binding="{Binding Path=Amount, StringFormat=C}" Header="Amount" />
这篇关于在DataGrid格式的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文