• We've upgraded our forums. Please post any issues/requests in this thread.

How can we change the header font color of WPF group box

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#2
What was stated in the link you posted worked for me.
Code:
<GroupBox Height="100" Width="200">
  <GroupBox.Header>
    <Label Foreground="Red">My Red GroupBox Header</Label>
  </GroupBox.Header>
</GroupBox>
Once you define the Header's Label in the above manner in code you then be able to click on it in the visual editor as see all of the Label's properties and will be able to use the property bar.
 

MrSeanKon

New Member
Joined
Nov 14, 2006
Messages
267 (0.07/day)
Likes
73
Location
Athens in love with Anna :)
#3
But if we add two buttons for example something is going mystery and I am getting :mad: :mad:
Check the simple WPF programs in attachment.
Damn many headaches cos WPF during the first days....
 

Attachments

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#4
I didn't run the code and you didn't really explain what was not exactly working, but it looks like you need to put the buttons inside the groupbox
Code:
<GroupBox ...>
   <GroupBox.Header ...>
      <Whatever ....>
   </GroupBox.Header>
   <Button ...></Button>
   <Button ...></Button>
</GroupBox>
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
20,923 (6.24/day)
Likes
10,023
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#5
Highly recommend putting some kind of container (e.g. a Grid) in the GroupBox instead of having the buttons land where they may.
 

MrSeanKon

New Member
Joined
Nov 14, 2006
Messages
267 (0.07/day)
Likes
73
Location
Athens in love with Anna :)
#6
It is better to open the code in Visual Studio (when you have free time) and you will understand easily what is going mystic
But let me to explain you right now.
I define a groupbox which has a header and two buttons inside (button_EN & button_GR). Pressing a button translates the controls of WPF form from English to Greek and vice versa (buttonEN_Click & buttonGR_Click events).
If the main XMAL file is this:

Code:
<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Header's color and font change" Height="150" Width="300" ResizeMode="NoResize">
    <Grid>
        <GroupBox Name="grouplang" BorderThickness="3" Margin="20,10,30,20">
            <GroupBox.Header>
                <TextBlock FontSize="14" Foreground="Green" FontWeight="Bold" FontFamily="Times New Roman">Language</TextBlock>
            </GroupBox.Header>
        </GroupBox>
        <Button Content="Ελληνικά" Height="23" HorizontalAlignment="Left" Margin="50,50,0,0" Name="buttonGR" VerticalAlignment="Top" Width="75" Click="buttonGR_Click" />
        <Button Content="English" Height="23" HorizontalAlignment="Left" Margin="150,50,0,0" Name="buttonEN" VerticalAlignment="Top" Width="75" Click="buttonEN_Click" />
    </Grid>
</Window>
after pressing a button damn header's color & font's size/family changes....
Adding some definitions for TextBlock only the color changes (font family & size not).

Code:
<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Here only the color changes" Height="150" Width="300" ResizeMode="NoResize">
    <Grid>
        <GroupBox Name="grouplang" BorderThickness="3" FontSize="14" Foreground="Green" FontWeight="Bold" FontFamily="Times New Roman" Margin="20,10,30,20">
            <GroupBox.Header>
                <TextBlock FontSize="14" Foreground="Green" FontWeight="Bold" FontFamily="Times New Roman">Language</TextBlock>
            </GroupBox.Header>
        </GroupBox>
        <Button Content="Ελληνικά" Height="23" HorizontalAlignment="Left" Margin="50,50,0,0" Name="buttonGR" VerticalAlignment="Top" Width="75" Click="buttonGR_Click" />
        <Button Content="English" Height="23" HorizontalAlignment="Left" Margin="150,50,0,0" Name="buttonEN" VerticalAlignment="Top" Width="75" Click="buttonEN_Click" />
    </Grid>
</Window>
Thus my question is how can I access groupbox's header color during execution adding the necessary commands in C#?
For WF case it is simple because WF design is based on C#.
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#7
Sorry, Sean. I didn't have time to dig into it father this morning as I had to leave for work. I will poke around with it when I get home tonight.
 

MrSeanKon

New Member
Joined
Nov 14, 2006
Messages
267 (0.07/day)
Likes
73
Location
Athens in love with Anna :)
#8
OK don't worry; take your time!
But I have to continue a bit....
Well as I try to be familiar with this new field (WPF) the problem is inside XAML commands.
Pressing a button groupbox's header color is reset to the default value (blue).
Thus we have to add something equivalent in C#.
For example look the photo. It is a conversion from XAML to C#.
I am seeking to MSDN forums to find a small part of code but I have not found yet.
 

Attachments

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#9
Sorry for the delay, I'm really busy lately.

The reason you are having problems is that you are modifying the header in the button events instead of the TextBlock, so basically you are saying "replace the TextBlock with this header content." Since you are not specifying any font or color characteristics it is using the system default.

Give the TextBlock a name, and then in your button events change the text by using textBlockName.Text="Language" (or the Greek equivalent). This will change the text in the TextBlock but not any of its other properties.
 

MrSeanKon

New Member
Joined
Nov 14, 2006
Messages
267 (0.07/day)
Likes
73
Location
Athens in love with Anna :)
#10
The photo shows what Kreij means.
Thanks buddy!
I could not think this solution!
I got many times in mess and was very angry with WPF programming. But I must overtake the problems!

As we live we will learn Socrates
 

Attachments