How to remove global FocusVisualStyle to all the Controls? - wpf

I met the same problem as Deactivate FocusVisualStyle globally.
But none of the answers can work.
So, I just want to set all the Controls in my application FocusVisualStyle="{x:Null}", any
effecive way to achieve this?
I don't want to set each control separately.

How about just putting this into your Application.Resources?:
<Style TargetType="{x:Type Control}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
To also affect non-controls as well, try this instead:
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
As Control is derived from FrameworkElement, they will all use this Style also.

Related

Implicit Styles (still) not working on SciChart WPF

I had asked this question before, in regards to the AxisPanel:
Implicit styles not working in SciCharts WPF?
I'm starting to notice that there are more issues further down... not sure if this was fixed in the "last" update or not.
If I create an implicit style, say...
<Style TargetType="{x:Type SciCharts:SciChartSurface}" BasedOn="{x:Type SciCharts:SciChartSurface}">
<Setter Property="BorderBrush" Value="Red" />
</Style>
That the style is completely ignored. It's placed above the actual SciChart in the scheme of all things, such that my hierarchy is:
<SomeControl>
<SomeControl.Resources>
Implicit Styles Here
</SomeControl.Resources>
<Some Other Control />
<SciChartSurface />
</SomeOtherControl>
The BorderBrush itself is pulling from the DefaultStyle, supposedly (checking with Snoop) and not the ImplicitStyle (Snoop does a marvelous job of telling us which it pulls from -- but not where that Style is located). The BorderBrush is bound to the DefaultStyle and completely ignores whatever is set in the Implicit Style.
I'm not sure if there is something I'm missing, but the end result is that we have some application-wide settings we'd like to make to all of our SciCharts and very little support to do it, aside from literally having to specify a style on every element.
I'm curious if, per my last question (linked above), that this was a "large" issue for more than just AxisPanel and extended to all of the SciChart's controls/elements -- and more than just AxisPanel was updated to support DefaultStyleKey?
Thanks in Advance!
I found the error, in this case it appears to be between keyboard and chair :P
You need
<Style TargetType="{x:Type s:SciChartSurface}" BasedOn="{StaticResource {x:Type s:SciChartSurface}}">
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="Margin" Value="10"/>
<Setter Property="BorderThickness" Value="10"/>
</Style>
not
<Style TargetType="{x:Type s:SciChartSurface}" BasedOn="{x:Type s:SciChartSurface}">
<Setter Property="BorderBrush" Value="Red" />
<Setter Property="Margin" Value="10"/>
<Setter Property="BorderThickness" Value="10"/>
</Style>
I put together an example showing how to set implicit styles on SciChartSurface, NumericAxis and AxisPanel here..
This contains how to set the style on the AxisPanel implicitly:
AxisBase.AxisPanelStyle was added in build v5.1.0.11306 as mentioned here.

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.

MahApps.Metro change ToggleSwitch style

I'm testing wpf applications using MahApp.Metro.
Somehow I'm not able to change the style of the ToggleSwitch. I just want to change simple properties like foreground or background of the switch. What am I doing wrong?
Mainwindow.xaml
<Style x:Key="flyoutToggleSwitchStyle" TargetType="{x:Type Controls:ToggleSwitch}" BasedOn="{StaticResource {x:Type Controls:ToggleSwitch}}">
<Setter Property="BorderBrush" Value="WhiteSmoke"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Yellow"/>
<Setter Property="OnLabel" Value="Yes"/> <!--<<<---THIS WORKS!!-->
<Setter Property="OffLabel" Value="No"/>
</Style>
<Controls:ToggleSwitch Style="{StaticResource flyoutToggleSwitchStyle}">
<Controls:ToggleSwitch.Header>
<TextBlock>
Test
</TextBlock>
</Controls:ToggleSwitch.Header>
</Controls:ToggleSwitch>
Now there is a new ToggleSwitch property called SwitchForeground which allows changing the colour for ON position (tested on v0.14).
Example:
<controls:ToggleSwitch SwitchForeground="{StaticResource MyGreen}" />
The problem is that in the Mahapps.Metro ToggleSwitch most of the properties can not be changed within a style, because there is no TemplateBinding or Key defined in the original template definition.
So the style can only be changed by creating a new template. For this the ToggleSwitch and the ToggleSwitchButton templates have to be changed.
Issue on GitHub
Source of the templates

DataGrid2D set TextAlignment in DataGridCell

I am using the DataGrid2D posted here. I can't seem to figure out a way to align the Text inside the Cells (i.e. right, center, left). For the default WPF4 DataGrid I just set
<Style x:Key="GridTextColumnStyleLeftAligned" TargetType="TextBlock">
<Setter Property="TextAlignment" Value="Left" />
<Setter Property="Margin" Value="2" />
<Setter Property="TextWrapping" Value="WrapWithOverflow" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
Here TextAlignment does the trick. But when using the ItemsSource2D Property to bind it to a 2-dimensional Array this does not work anymore.
Does anybody have a suggestion?
I found the problem: I am using the Alternative Style which the DataGrid2D Provides. There we already have this definiton:
<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}" >
<Setter Property="TextBlock.TextAlignment" Value="Center" />
...
If I change it here it works. I will have to rewrite the class a bit, for me to set the Alignment in XAML instead of with a style.

How to make WPF DataGrid Column Header transparent

I am trying to make the column header of my WPF Datagrid to be transparent.
I am able to set it to a color without problem, but I can't have it transparent. Here is what I tried:
<Style x:Key="DatagridColumnHeaderStyle" TargetType="{x:Type tk:DataGridColumnHeader}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="#C2C4C6" />
</Style>
<Style x:Key="DashboardGridStyle" TargetType="{x:Type tk:DataGrid}">
<Setter Property="ColumnHeaderStyle" Value="{StaticResource DatagridColumnHeaderStyle}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="RowBackground" Value="Transparent" />
</Style>
<tk:DataGrid Style="{StaticResource DashboardGridStyle}" >
...
</tk:DataGrid>
With this code, it seems to take the default brush.
What am I missing?
I used Snoop to take a look at what was happening. It seems that another DataGridColumnHeader is always created behind the one you can modify, and it's not affected by changes on styles. When you set a transparent background, in fact is being correctly applied, so what you see is that ghost header behind (which has the usual grey background).
If you apply a coloured background and play with Opacity, you will see how the two colours are mixed. I don't know if this can be solved.
With the answer from Natxo (thanks!), I was able to find a solution. And it is a simple one too!
Knowing that there was another DataGridColumnHeader behind the one we can modify through the ColumnHeaderStyle, I just had to set a style that will affect all DataGridColumnHeader:
<Style TargetType="{x:Type tk:DataGridColumnHeader}">
<Setter Property="Background" Value="Transparent" />
</Style>

Resources