Extended WPF toolkit DoubleUpDown IsEnabled trigger changing background not working - wpf

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.

Related

Different background color for selected RibbonTab

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

How do you change the background on TextBlock on press or on click?

I am able to get a TextBlock in XAML to have an IsMouseOver trigger, but what about an IsPressed or IsFocused. I want the TextBlock background to change color when the user clicks on the TextBlock. This is TextBlock NOT a TextBox. It there a way to do it in only XAML.
I tried:
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="Blue"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="Blue"></Setter>
</Trigger>
And these don't seem to work at all. Is there another property or is it even possible to do on a TextBlock.
Thanks in advance.
Wrap it in a ToggleButton, change ToggleButton.Template to a lone ContentPresenter in a Border. Hook up Background to Border.Background via TemplateBinding.
This gives you IsChecked to trigger on and just shows text with a background color.

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...

WPF ComboBox ControlTemplate Background problem

This is an example of a ComboBox's ControlTemplate.
CLICK HERE
I've tried to set the Background / add a trigger to change the background when the ComboBox is focused (with a tab key for example),
both without success.
I don't even understand why it isn't included by default !
(compared to the original generic template)
Do you mean change the background of the ComboBoxItem when it is focused? Its not normal to change the background of an entire ComboBox. Keep in mind that the template is different for editable ComboBoxes.
From looking at the template you referenced, the Background property is used for the ComboBox dropdown. So you're trigger needs to target that outter most Grid. Did you try adding triggers like these?
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter TargetName="[outtermostgrid]" Property="Background" Value="Red" />
</Trigger>
<Trigger Property="IsDropdownOpen" Value="True">
<Setter TargetName="[outtermostgrid]" Property="Background" Value="Red" />
</Trigger>

WPF Trigger for IsSelected in a DataTemplate for ListBox items with Blend

I wanted to change the Foreground color when I selected a listboxItem and I did it using this bit of code:
<DataTrigger Binding="{Binding
RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
<Setter TargetName="descriptionTB" Property="Foreground" Value="#000"/>
</DataTrigger>
You can find the answer here.
But if I want a designer to do this in Blend, how would he do it without drilling into xaml?
Thank you
Artur,
The Triggers designer in Expression Blend only allows adding and modifying EventTriggers and Property triggers. I haven't found a way to add DataTriggers with Blend. I'm also not sure how to set RelativeSource Binding using Blend either. I've always handed code the XAML for test and use Blend for everything else.
Maybe I'm misunderstanding the question but can't you just create a style resource for descriptionTB and let the designer only deal with that style definition and not the binding?
<DataTrigger Binding="..">
<Setter TargetName="descriptionTB" Property="Style" Value="{StaticResource DescriptionTextBoxStyle}" />
</DataTrigger>
In the resources section of your control or window you add the style definition:
<Style TargetType="{x:Type TextBox}" x:Key="DescriptionTextBoxStyle">
<Setter Property="Foreground" Value="#000" />
</Style>
If you want to further isolate the designer from the mechanics of the UI you can create a resource dictionary in a separate xaml file in which you can collect all styles meant for the designer. Then you can merge that resource dictionary with your control's or application's main resources.

Resources