Home > Blockchain >  WPF: The bottom line of Label in DataGrid is disappeared
WPF: The bottom line of Label in DataGrid is disappeared

Time:09-09

I have a DataGrid and I set DataGrid.Columns combined with many DataGridTemplateColumn.

One of DataGridTemplateColumn needs to show FileName.

I use Label in DataTemplate and binding FileName, and Label's ToolTip also Binding the same FileName.

                <DataGridTemplateColumn Header="{Binding Data.ImageNameStrings, Source={StaticResource proxy}}" Width="50" MinWidth="48">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Label Content="{Binding FileName}">
                                <Label.ToolTip>
                                    <TextBlock Text="{Binding FileName}" Padding="6,2" Background="White" Foreground="#353535" FontSize="14"/>
                                </Label.ToolTip>
                            </Label>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

I expect it will show the same result, but when the filename has a bottom line, the label content's bottom line disappears.

The tooltip is correct.

enter image description here

Next, I try the filename that has two bottom lines, it will lose one bottom line.

enter image description here

What is going on?

Why bottom line disappears?

Please help me, thanks!

CodePudding user response:

It is Underscore (not bottom line). You can use TextBlock instead of Label.

<TextBlock Content="{Binding FileName}">
    <TextBlock.ToolTip>
        <TextBlock Text="{Binding FileName}" Padding="6,2" Background="White" Foreground="#353535" FontSize="14"/>
    </TextBlock.ToolTip>
</TextBlock>

Underscore is used in Lable as shortcut, take a look at this example

<Button Width="100" Command="{Binding ClickMeCommand}">
    <Label Content="Click_Me" />
</Button>

Here, the button will look like this

enter image description here

and if you press on m key on your keyboard, the command will be executed.

  • Related