Different background color for selected RibbonTab - wpf

I have a WPF Window with a Ribbon with a dark background color (SolidColorBrush)
I have set the font color of the tabs to white, but that's not readable in the selected tab. So I would like to have a black background in the selected tab (or a black font color would also work).
My app.xaml contains this code to style it:
<Application.Resources>
<ResourceDictionary>
<Style x:Key="SelectedRibbonTab" TargetType="RibbonTab">
<Setter Property="Background" Value="Black"></Setter>
</Style>
<Style TargetType="RibbonTab">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="HeaderStyle" Value="{DynamicResource SelectedRibbonTab}"></Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="RibbonTabHeader">
<Setter Property="Foreground" Value="White"></Setter>
</Style>
</ResourceDictionary>
</Application.Resources>
It is clearly not working, any solutions how I can fix this?

You can use a single style to change the header text color (Foreground) using IsRibbonTabSelected.
<Style TargetType="RibbonTabHeader">
<Setter Property="Foreground" Value="White"/>
<Style.Triggers>
<Trigger Property="IsRibbonTabSelected" Value="True">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
Changing the background of a ribbon tab is not recommended, as it is not that trivial. The ribbon and ribbon tab backgrounds can be customized by setting the Background property of the Ribbon itself. This will in turn adapt the background color of all tabs in all states. These backgrounds use gradients and are defined in the respective control templates. Again, it is not easy to even get these control templates, see:
How to customize the WPF Ribbon 4.5 (styles, templates, etc.)
If you want to try it nevertheless, here is a related post that links an MSDN forum answer that offers a possible style and control template that might be adapted. However, I recommend to simply use the style above.
Changing Windows.Ribbon background color
Placing a Background to a Tab on a Ribbon Control
An alternative is to use the Fluent.Ribbon instead, which offers more support for customization.
Fluent.Ribbon GitHub
Fluent.Ribbon NuGet package
Fluent.Ribbon Docs on Creating Custom Themes

Related

xctk:IntegerUpDown custom style to hide ButtonSpinner

On the xctk:IntegerUpDown, I would like the textbox border and the ButtonSpinner to only be visible when focused or mouseover.
It is easy enough to turn the border on/off using a <Style.Triggers> section.
It is also possible to control the ShowButtonSpinner property.
However, the content of the TextBox jumps to the right if I set ShowButtonSpinner=False.
I would like to simply hide the ButtonSpinner without TextBox contents jumping around.
Like this:
How can I get access to the appropriate property?
your question helped me to find ShowButtonSpinner property which I needed to hide up and down buttons
i can suggest a workaround with setting a fixed Padding for content when buttons are hidden. Value 0,0,17,0 seems ok to me (Win7, wpf toolkit version v2.6.0.0)
<xctk:IntegerUpDown.Style>
<Style TargetType="xctk:IntegerUpDown">
<Setter Property="Padding" Value="0,0,17,0"/>
<Setter Property="ShowButtonSpinner" Value="False"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Padding" Value="0"/>
<Setter Property="ShowButtonSpinner" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</xctk:IntegerUpDown.Style>
another simple thing is to align text to left side via property
<xctk:IntegerUpDown TextAlignment="Left"/>

How can I easily change the style of WPF TextBox when it gets focused?

I have a TextBox in my WPF app, with background color "Blue". When it receives focus, the background color changes to "White" by default. I want the background color to have another color when the TextBox gets focused (say "DodgerBlue").
All I can find in the web are amazingly examples of styles or templates, defining all possible VisualStates of the TextBox.
Is it not possible to create a short template targeting only that specific situation (i.e. when the TextBox has focus)?
Thanks.
You can use a simple style trigger:
<TextBox>
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="Tomato" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
That should do...

Implicity style for BarDataPoint is not applied

I am currently working on creating a theme for charts.
Beside other things, I want to make the bars in BarSeries have a flat look(without borders).
I want to make it to work with implicit styling so I added a Style to BarDataPoint(without a Key because it needs to work by implicit styling) but it is not applied.
Any idea why is it is not applied?
Is it because of DataPointStyle style from Palette which is applied instead?
What I am trying to do is to change the look of the BarDataPoint but still have the colors from the palette applied. And also try to make this work by pure XAML(if possible).
In order to make this work, the only way I see is by changing DataPointStyle(in each ResourceDictionary from Chart.Palette) to have TargetType set to BarDataPoint and Template set to my template implementation:
<toolkit:Chart.Palette>
<toolkit:ResourceDictionaryCollection>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="toolkit:BarDataPoint" BasedOn="{StaticResource BarDataPointStyle}">
<Setter Property="Background" Value="Yellow" />
<Setter Property="BorderBrush" Value="Black" />
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="toolkit:BarDataPoint" BasedOn="{StaticResource BarDataPointStyle}">
<Setter Property="Background" Value="Red" />
<Setter Property="BorderBrush" Value="Black" />
</Style>
</ResourceDictionary>
</toolkit:ResourceDictionaryCollection>
</toolkit:Chart.Palette>
But since this is for implicit style for Chart control, how would that work if I have a Char control with a different type of series, for example a Chart with ColumnSeries? I don't think the DataPointStyle will work in this case because it is targeting the BarDataPoint type(I suppose the app will crash).
Am I forced to create different Chart styles with different keys(each style having DataPointStyle changed to target different control template)?
But then, how will that work for a Chart control with several different series?
I also tried to use an implicit style for toolkit:BarDataPoint in the palette's resource dictionary like this, but without success:
<Setter Property="Palette">
<Setter.Value>
<toolkit:ResourceDictionaryCollection>
<ResourceDictionary>
<SolidColorBrush x:Key="Background"
Color="#FFCA294D" />
<Style TargetType="toolkit:BarDataPoint">
<Setter Property="Template"
Value="{StaticResource BarDataPointTemplate}" />
<Setter Property="Background"
Value="{StaticResource Background}" />
</Style>
I tried to look to themes like JetPack but they don't seem to do what I want.
Thanks!
sorry for late update.
check this solution. may help others too
Silverlight 4: Chart Toolkit Color Set

Extended WPF toolkit DoubleUpDown IsEnabled trigger changing background not working

I am using an extended WPF control, which is DoubleUpDown.
For this control a have defined a style and within it a trigger for IsEnabled property.
<Style TargetType="{x:Type extToolkit:DoubleUpDown}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Pink"/>
</Trigger>
</Style.Triggers>
</Style>
For IsEnabled property I am using a binding from the ViewModel.
The problem is that when the control IsEnabled property is False the background is not all filled with pink, the pink color appears only between Up and Down buttons (See image).
How can I resolv this in order to fill all the control with the new pink color?
Thank you for your help.
Try using the latest source code. Make sure to compile the project located under the Main folder.

WPF Focus on "run" element

I would like to change the background of the Run that has the focus in a FlowDocument in a RichTextBox.
I would like to provide to my users a visual cue as to which Run element they are currently editing and I think a light background would be the best way for my application.
I see that the Run has Focusable (which I set to true), IsFocused, FocusVisualStyle, GotFocus, etc. but none of those properties or events seam to work.
Thank you for any help you can give.
You can use a data trigger to get the effect you want. Here's an example:
<Style TargetType="{x:Type RichTextBox}">
<Style.Triggers>
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" Value="LightGrey" />
</Trigger>
</Style.Triggers>
</Style>

Resources