猿问

在WPF数据绑定中添加其他字符

我是WPF应用程序的新手,我有一个问题。

是否可以为数据库中的每一行绑定添加其他字符?

我已经拖放了数据集以创建一个数据网格列表。它将自动生成用于数据绑定的代码。我想在{Percentage}数据的后面添加'%'符号。

<DataGridTextColumn x:Name="percentageColumn" Binding="{Percentage}" Header="Percentage" Width="SizeToHeader"/>


慕森卡
浏览 297回答 2
2回答

ITMISS

该示例完美地回答了这个问题。只需将stringformat与绑定一起使用即可。<DataGridTextColumn&nbsp;x:Name="percentageColumn"&nbsp;Binding="{Percentage,StringFormat={}{0}%}"&nbsp;Header="Percentage"&nbsp;Width="SizeToHeader"/>

慕桂英4014372

除了使用“ DataGridTextColumn”,您还可以使用“ DataGridTemplateColumn”来满足您的要求,如下所示,您可以在百分比值旁边附加任何字符串。`<DataGridTemplateColumn Header="Percentage">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <DataGridTemplateColumn.CellTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <DataTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Text="{Binding Percentage}"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextBlock Text=" %"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </DataTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </DataGridTemplateColumn.CellTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </DataGridTemplateColumn>`
随时随地看视频慕课网APP
我要回答