Reputation: 2947
I have a DataTable
with columns typeof(string)
. I am adding strings to this table and I need to have some of text in bold. My string looks like that:
row["UserData"] = user.Name + "\n" + user.Description + "\n" + user.Number + "\t" + user.Date;
Is it possible to make user.Name
in this code bold?
I am using .NET 4.0 and WPF.
Upvotes: 1
Views: 14368
Reputation: 196
Bolding text in DataGrid using DataGridRow: WPF DataGrid Example
<Style x:Key="RowStyle" TargetType="{x:Type dg:DataGridRow}">
<Setter Property="ValidationErrorTemplate">
<Setter.Value>
<ControlTemplate>
<Grid>
<Ellipse Width="12" Height="12"
Fill="Red" Stroke="Black"
StrokeThickness="0.5"/>
<TextBlock FontWeight="Bold" Padding="4,0,0,0"
Margin="0" VerticalAlignment="Top" Foreground="White" Text="!"
ToolTip="{Binding RelativeSource={RelativeSource
FindAncestor, AncestorType={x:Type dg:DataGridRow}},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This link also shows how to bold a StackPanel TextBlock.
Upvotes: 2
Reputation: 51
Where is this being shown?
Is this a plain text concatenated string you are trying to make bold, is it HTML, or are you wanting the user.Name portion of the code in the IDE to display as bold?
If it's plain text, there isn't much you can do. Displaying the string in some email clients will show as bold if you surround it with asterisks (*).
For HTML, you can surround the user.Name with either CSS or a strong/bold tag:
row["UserData"] = "<strong>" + user.Name + </strong>" + "\n" + user.Description + "\n" + user.Number + "\t" + user.Date;
or
row["UserData"] = "<span style='font-weight: bold;'>" + user.Name + "</span>" + "\n" + user.Description + "\n" + user.Number + "\t" + user.Date;
Upvotes: 1
Reputation: 36072
DataTable is just a data store - it doesn't control the display of the data. When you bind a ListView or other WPF control to the DataTable, you can style the columns of the control to display one of the columns text in bold.
Upvotes: 3
Reputation: 10113
I'm 99% sure you can only style columns of a DataTable, not the data within them.
Upvotes: 1
Reputation: 184376
Strings are just text, if you want to format text you have multiple ways of doing so but i do not know of anything "native". e.g. use XML markup around user.Name
to encode the formatting as text, that then can be used by some control which displays it to adjust the rendering.
Upvotes: 4