0

I'm new in WPF application and i have a question.

Is it possible to add additional character for each row bind from database?

I've drag and drop dataset to create a list of datagrid. It will automatically generate codes for data binding. I want to add '%' symbol on the back of {Percentage} data.

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

This example kinda confuse me a bit.

S. Ideal
  • 15
  • 4

2 Answers2

1

The example answers it perfectly. Just use stringformat with the binding.

<DataGridTextColumn x:Name="percentageColumn" Binding="{Percentage,StringFormat={}{0}%}" Header="Percentage" Width="SizeToHeader"/>
Shivani Katukota
  • 859
  • 9
  • 16
0

Instead of using 'DataGridTextColumn', you can use 'DataGridTemplateColumn' to achieve your requirement like below and you can append whatever string next to your percentage value.

`<DataGridTemplateColumn Header="Percentage">
                <DataGridTemplateColumn.CellTemplate>                        
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">                               
                            <TextBlock Text="{Binding Percentage}"/>
                            <TextBlock Text=" %"/>
                        </StackPanel>                            
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>`
IndraJeyan
  • 119
  • 7