Style of Controle At various Event - wpf

Could anyone tell what would be the style of the Label or Button at various event shows in the below image.
1. MouseOver
2 MousePressed and Control Selected

You can have a look at Style triggers. To figure out what properties you need you can have a look at the UIElement.
For example it can be something like:
<Style x:Key="Triggers" TargetType="Button">
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property = "Background" Value="LightGray"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property = "BorderBrush" Value="Blue"/>
</Trigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property = "BorderBrush" Value="LightGray"/>
</Trigger>
</Style.Triggers>
</Style>
The above style does not recreate the look of the button from the image, it's just a sample on how it can be done.
You can have a look at the Button class to see what properties you can change.

If I understood your question properly, I think you can change the opacity on MousePressed and Mouseover events.

Related

Repeat Button Style Setter/Triggers Doesn't Work

I'm using the Extended WPF Toolkit's IntegerUpDown control.
I was able to stylize the arrow buttons in a previous question.
Before
After
I've run into some additional style problems:
I'm using PresentationFramework.Aero and Aero2.
<!-- RepeatButton Style -->
<Style x:Key="{x:Static theme:ResourceKeys.SpinnerButtonStyleKey}" TargetType="RepeatButton">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="DarkBlue"/>
<Setter Property="BorderBrush" Value="Transparent" />
</Trigger>
</Style.Triggers>
</Style>
Link to the full XAML: http://pastebin.com/ETYgHEpz
The IsEnabled False Trigger will not override the Disabled Background or Border Color. It always stays White, I need it Transparent. However I can override the Opacity and BorderThickness. (Windows 10):
Cannot change the IsMouseOver Background Color, always Light Blue. (Windows 10):
Windows 7 always displays a White Border, even if BorderThickeness is 0 and Color is Transparent or {x:Null}:
I think it is being overriden by a Control Template, but IntergerUpDown doesn't have a RepeatButton Style within the Control Template and I've had trouble trying to add one. I had to create the Style outside.
some properties won't work when you set via Style setters. This is because of Dependency Property Value Precedence. Try changing the values in ControlTemplate triggers.

Set default style to listviewitem

Everytime listviewitem gets selected, automatically its foreground gets set to white.
How can I prevent this behavior in codebehind?
I tried this, but without effect:
<Trigger Property="IsSelected" Value="False" > or True
It doesn't exactly answer the question, because there is no code behind in this solution. But in my opinion, code behind is not the way to go here.
<Style TargetType="ListBoxItem">
...
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Some color"/>
</Trigger>
</Style.Triggers>
</Style>

React on control property in a child element

I'm creating a WPF UserControl and have defined a dependency property named "Orientation" in it. It's of the type Dock that allows me to set the values Top, Bottom, Left and Right. The UserControl also contains a Border element in its XAML. Depending on the value of the Orientation property, the border shall appear on one side. Here's my triggers I have defined so far:
<Trigger Property="Orientation" Value="Bottom">
<Setter Property="BorderThickness" Value="0,1,0,0"/>
</Trigger>
<Trigger Property="Orientation" Value="Top">
<Setter Property="BorderThickness" Value="0,0,0,1"/>
</Trigger>
<Trigger Property="Orientation" Value="Left">
<Setter Property="BorderThickness" Value="0,0,1,0"/>
</Trigger>
<Trigger Property="Orientation" Value="Right">
<Setter Property="BorderThickness" Value="1,0,0,0"/>
</Trigger>
I've now tried to use these triggers in the Border's style, but they can't find the Orientation property. I've then tried to use it in the UserControl's style, with the TargetName set to my Border, but TargetName cannot be set.
How does the correct XAML code for this look like?
In your Border Style use DataTrigger instead of Trigger e.g
<DataTrigger Binding="{Binding Orientation, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="Bottom">
<Setter Property="BorderThickness" Value="0,1,0,0"/>
</DataTrigger>
similarly update all the triggers

Clear binding using XAML

I'm creating a wpf application, which holds a text box.
When the text box is disabled (the default state) I'm binding it to something, but when the user double click the text box it's changing its state to enabled and the user can edit it.
But when I type something after the text box is enabled, it's deleted every second because of the trigger (maybe the ui is updating and the trigger with him). When I did using code and just cleared the binding after double click it worked fine. But I don't want to do it through code, I know that I'm just missing a little thing for the XAML to work.
This is my current XAML:
<Style.Triggers>
<Trigger Property="TextBox.IsEnabled" Value="False">
<Setter Property="Text" Value="{Binding some binding}"/>
</Trigger>
<Trigger Property="TextBox.IsEnabled" Value="True">
<Setter Property="Text" Value="{x:Null}"/>
</Trigger>
</Style.Triggers>
Thanks!
Would it help to set the Binding but change its direction to OneWayToSource?
<Style.Triggers>
<Trigger Property="TextBox.IsEnabled" Value="False">
<Setter Property="Text" Value="{Binding someBinding}"/>
</Trigger>
<Trigger Property="TextBox.IsEnabled" Value="True">
<Setter Property="Text" Value="{Binding Path=someBinding, Mode=OneWayToSource}"/>
</Trigger>
</Style.Triggers>

WPF ListView : Header styling

I want to have a ListView with columns and a particular style:
The background for ALL column headers should be transparent except when the mouse is over in one of them.
When this happends, the column's background in which the mouse is over should be yellow and all the color in the other columns should be, let's say, blue.
I've tried playing with GridViewColumnHeader template, but that seems to change only the active column background. Any help?
In order to do this, I think you're going to have to replace the entire ListView style. Microsoft has an example.
You'll have to put a Border around the GridViewHeaderRowPresenter in the ScrollViewer style shown in there and add an IsMouseOver trigger to set the background of that Border to Blue.
Then, of course, you'll need an IsMouseOver trigger on the GridViewColumnHeader template to make the background yellow.
If you need any further explanation, please ask.
--
HTH, Dusty
Finally, I found a way to do this: basically, you set a trigger that will see if the parent GridViewHeaderRowPresenter is selected. All headers will then return true to that property.
Then you check if the header has the mouse over it and only the selected header will return true.
The result will be something like this:
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type GridViewHeaderRowPresenter}},
Path=IsMouseOver}"
Value="True">
<Setter TargetName="HeaderBack" Property="Background"
Value="{StaticResource HeaderActiveColumnBackground}"/>
<Setter TargetName="PART_HeaderGripper" Property="Background"
Value="{StaticResource VerticalLineColor}"/>
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="HeaderBack" Property="Background"
Value="{StaticResource HeaderSelectedColumnBackground}"/>
</Trigger>
<Trigger Property="HasContent" Value="false">
<Setter TargetName="HeaderBack" Property="Background"
Value="{StaticResource HeaderDefaultColumnNoContentBackground}"/>
<Setter TargetName="PART_HeaderGripper" Property="Background"
Value="{StaticResource HeaderDefaultColumnNoContentBackground}"/>
</Trigger>
</ControlTemplate.Triggers>

Resources