WPF DataGridTextColumn - 使用 '-'而不是“0”
如何让 DataGridTextColumn
显示 '-'(连字符)而不是 0。
以下是数据网格当前的设置方式:
<Grid>
<DataGrid x:Name="EmployeeHours"
AutoGenerateColumns="False"
ItemsSource="{Binding EmployeeHoursLastWeek}"
Width="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="PerceptionistID"
Binding="{Binding PerceptionistID}"
Width="100" />
<DataGridTextColumn Header="Week Of"
Binding="{Binding WeekOf, StringFormat={}{0:MM/dd/yyyy}}"
Width="75" />
<DataGridTextColumn Header="Regular Hours"
Binding="{Binding WorkHours}"
Width="100" />
<DataGridTextColumn Header="PTO Hours"
Binding="{Binding PTOHours}"
Width="100" />
<DataGridTextColumn Header="Holiday Hours"
Binding="{Binding HolidayHours}"
Width="100" />
</DataGrid.Columns>
</DataGrid>
</Grid>
PTOHours 和 HolidayHours 通常为 0,如果任何带有 0 的单元格显示“-”,则可以更轻松地识别具有非 0 值的单元格。
How can I get a DataGridTextColumn
to display a '-' (hyphen) instead of 0.
Here is how the data grid is currently setup:
<Grid>
<DataGrid x:Name="EmployeeHours"
AutoGenerateColumns="False"
ItemsSource="{Binding EmployeeHoursLastWeek}"
Width="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="PerceptionistID"
Binding="{Binding PerceptionistID}"
Width="100" />
<DataGridTextColumn Header="Week Of"
Binding="{Binding WeekOf, StringFormat={}{0:MM/dd/yyyy}}"
Width="75" />
<DataGridTextColumn Header="Regular Hours"
Binding="{Binding WorkHours}"
Width="100" />
<DataGridTextColumn Header="PTO Hours"
Binding="{Binding PTOHours}"
Width="100" />
<DataGridTextColumn Header="Holiday Hours"
Binding="{Binding HolidayHours}"
Width="100" />
</DataGrid.Columns>
</DataGrid>
</Grid>
PTOHours and HolidayHours are typically 0 and it would make it easier to identify cells with a value other than 0 if any cell with 0 displayed a '-' instead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用一个值转换器,
这里是转换器
希望这有帮助
you can use a value converter for it
here is the converter
hope this helps