I want to increase the size of the border of a DatePicker when it has focus. In the TextBox style the following works nicely when used with a border BorderBase in the ControlTemplate.
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsFocused" Value="true">
<Setter Property="BorderThickness" TargetName="BorderBase" Value="2"/>
<Setter Property="Padding" TargetName="BorderBase" Value="3"/>
</Trigger>
</ControlTemplate.Triggers>
For DatePicker this does not work since the DatePickerTextBox inside the DatePicker has the actual focus. On the DatePicker style page the visual states are listed. The TextBox does have a Focused state, but the DatePicker only has a Focused state for when the input invalid.
How do you guys suggest I tackle this problem?
What about setting your Trigger on HasKeyboardFocus instead of IsFocused? I think that one will return true if any child element contains focus
How about naming the TextBox and specifying a respective Trigger.SourceName?
Related
I am trying to change the background of a button with the IsMouseOver trigger. I have found many good answers on Stackoverflow but I am having a strange issue that I can't seem to find anyone else having. I have the following style defined
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Purple"/>
</Trigger>
</Style.Triggers>
</Style>
and using it with a button
<Button Content="Some Button"/>
My problem is that when I mouse over the background changes to Purple but then immediately changes to the standard windows blue color with my mouse still over the button. I expect that the background would stay purple until the mouse is no longer over the button. Does anyone know what could be the issue? Thanks.
The standard template for a Button uses a ButtonChrome component, which takes care of rendering the button according to the current Windows theme. Unfortunately, the ButtonChrome is not very customizable (basically it does everything in its OnRender handler), so it you want to make bigger changes to the appearance of the button, you'll have to write a custom template.
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"/>
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.
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>
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>