Clyde Eisenbeis

Clyde Eisenbeis

  • 1.3k
  • 63
  • 11.8k

How do I set ListBox item font to bold? - Continued #3

May 18 2024 1:50 PM

C# wpf --- This is "continuation" of c-sharpcorner.com/forums/how-do-i-set-listbox-item-font-to-bold-continued-sharp2.

Sam Hobbs and Abhishek Chadha, Thanks for the suggestions.  Unfortunately, they do not results in bold text.  Here is a larger segment of code in the xaml file:

<Window x:Class="PandemicGame.MainWindow"
        xmlns="... schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="... schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="... schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="... schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:PandemicGame"
        mc:Ignorable="d"
        ...>
    <Window.Resources>
        <LinearGradientBrush x:Key="GrayBlueGradientBrush" StartPoint="0,0" EndPoint="1,1">
            <GradientStop Color="DarkGray" Offset="0" />
            <GradientStop Color="#CCCCFF" Offset="0.5" />
            <GradientStop Color="DarkGray" Offset="1" />
        </LinearGradientBrush>
        <Style TargetType="{x:Type Button}">
            <Setter Property="FontFamily" Value="Arial Narrow"/>
            <Setter Property="FontSize" Value="15"/>
            <Setter Property="Background" Value="{StaticResource GrayBlueGradientBrush}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" ClipToBounds="True">
                            <Rectangle x:Name="innerRectangle" 
                                                HorizontalAlignment="Stretch" 
                                                VerticalAlignment="Stretch" 
                                                Stroke="Transparent" 
                                                StrokeThickness="5" 
                                                Fill="{TemplateBinding Background}" RadiusX="10" RadiusY="10" />
                            <DockPanel Name="myContentPresenterDockPanel">
                                <ContentPresenter x:Name="myContentPresenter" HorizontalAlignment="Center" Margin="5" Content="{TemplateBinding  Content}" TextBlock.Foreground="Black" />
                            </DockPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="{x:Type Label}">
            <Setter Property="FontFamily" Value="Arial Narrow"/>
            <Setter Property="FontSize" Value="15"/>
        </Style>
        <Style TargetType="{x:Type Menu}">
            <Setter Property="Background" Value="LightGray" />
            <Setter Property="FontFamily" Value="Arial Narrow"/>
            <Setter Property="FontSize" Value="15"/>
        </Style>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="FontFamily" Value="Arial Narrow"/>
            <Setter Property="FontSize" Value="15"/>
        </Style>
        <Style TargetType="{x:Type RichTextBox}">
            <Setter Property="FontFamily" Value="Arial Narrow"/>
            <Setter Property="FontSize" Value="15"/>
        </Style>
        <Style TargetType="{x:Type ScrollBar}">
            <Setter Property="Background" Value="LightGray" />
        </Style>
        <Style TargetType="ListBoxItem">
            <Setter Property="Height" Value="22" />
        </Style>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="Height" Value="22" />
        </Style>
        <Style TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="Background" Value="LightGray" />
        </Style>
    </Window.Resources>
<ListBox x:Name="gLBxReshuffledList1st" 
Margin="5,0,5,0" 
Foreground="#FF00FF" 
MouseDoubleClick="gLBxReshuffledList1stToInfectedCities_MouseDoubleClick">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="FontWeight" Value="Bold"/>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

The first segments of code are copies from code written many years ago.


Answers (1)