Removing DataGrid cell dotted border? - wpf

I want to remove the dotted border around Romance that can be seen in the above datagridcell. The border appears whenever i use the key board left-right navigation keys. How can i get rid of it ?

You have to clear out the FocusVisualStyle of the DataGridCells.
<DataGrid>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
</DataGrid.CellStyle>
...

Related

DataPicker Button influenced by a global styling on all Buttons

I'm maintaining a big old C#/WPF application in which a style has been set globally for all buttons It can sound ugly, but I can't change this without refactoring the whole app.
Here is an extract of this style:
<Style TargetType="Button">
<Setter Property="Height" Value="32"/>
<Setter Property="MinWidth" Value="96"/>
<Setter Property="Margin" Value="10"/>
</Style>
The problem is that when I want to use a DatePicker, this global style influenced the appearance of the DataPicker:
Is there a simple way to restore the default Margin, Height and MinWidth only for the Button inside the DatePicker?
You can override the Style for the Buttons locally. The following XAML sets the Style for all Buttons inside the DatePicker back to the default Style.
<DatePicker>
<DatePicker.Resources>
<!-- Default Style -->
<Style TargetType="{x:Type Button}"/>
</DatePicker.Resources>
</DatePicker>
Edit
As requested in the comments, a Style to fix this issue globally
<Style TargetType="{x:Type DatePicker}">
<Style.Resources>
<Style TargetType="{x:Type Button}"/>
</Style.Resources>
</Style>
Note: This Style should be placed in the same hierarchy-context as the Button Style.

WPF TabControl - How to remove Margin above inactive Tabs?

Any Ideas how to remove the Margin in the following image?
Checked it via Snoop. By default, the selected TabItem has a margin of -2,-2,-2,-1, so you can set this top margin for all tab items:
<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="Margin" Value="0,-2,0,0"/>
</Style>

How to style last (or first) child of StackPanel differently than the rest?

I'm applying styles to StackPanel:
<Style TargetType="{x:Type StackPanel}">
<Style.Resources>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextboxStyle}">
<Setter Property="Margin" Value="0,0,0,5"/>
</Style>
</Style.Resources>
</Style>
Basically, it adds margin on bottom of every TextBox in StackPanel. What is bad, that last child will have unnecessary margin. So I need to reset it to zero, but only for that last element. WPF is certainly not a CSS, which have :last-child selector and it's probably more quirky to do that.

MahApps setting style based on existing style has strange output

I copyied MahApps DataGrid's source code and It works fine if I change directly on the style such as setting HorizontalAlignment from left to right. But if I did
<Style BasedOn="{StaticResource MetroDataGridColumnHeader}" TargetType="{x:Type DataGridColumnHeader}"
x:Key="MetroDataGridColumnHeader1">
<Setter Property="HorizontalAlignment" Value="Right"></Setter>
</Style>
and replace the MetroDataGridColumnHeader with the new MetroDataGridColumnHeader1 inside DataGrid style, It gives strange output. Metro effects disappears.Any ideas?
You should set the HorizontalContentAlignment not the HorizontalAlignment.
<Style BasedOn="{StaticResource MetroDataGridColumnHeader}"
TargetType="{x:Type DataGridColumnHeader}"
x:Key="RightAlignmentMetroDataGridColumnHeader">
<Setter Property="HorizontalContentAlignment"
Value="Right" />
</Style>
Hope this helps.

WPF- Changing Tooltip background to Transparent

I am attempting to make it so that when I hover over a button in my application, the "tooltip" displays my wording, along with a transparent background, instead of the white background.
I am merely trying to change the tooltip default settings to a transparent background..
I have looked and looked, but to no success.. anyone have any ideas?
Thanks.
<Style x:Key="{x:Type ToolTip}"
TargetType="{x:Type ToolTip}">
<Setter Property="Background"
Value="Transparent" />
</Style>
Place this in the resource dictionary of your view, or for your application.
And this is the final style which sets the tooltip background to transparent:
<Style TargetType="{x:Type ToolTip}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Style>
Note that you need to set also the BorderBrush to Transparent, not only the Background.
The class ToolTip has property Background. See http://msdn.microsoft.com/en-us//library/system.windows.controls.tooltip_members.aspx. You can set Background to Transparent.

Resources