WPF application look and feel is different in Win7 & Win10 versions as shown in the attached figure. All the controls have red border but in Win10 the following behavior is noticed. Textboxes (on hover and selection) and comboboxes border changes to blue color in Win 10.
The applied style is as follows
<Style TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="#FFcecece" />
<Setter Property="Foreground" Value="#FF777777"/>
<Setter Property="BorderThickness" Value="1.6" />
</Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="BorderBrush" Value="#FFcecece" />
<Setter Property="Foreground" Value="#FF777777"/>
<Setter Property="BorderThickness" Value="1.6" />
</Style>
The red border is applied thru code behind as follows when the above behavior is noticed
textBox1.BorderBrush = Media.Brushes.Red;
textBox3.BorderBrush = Media.Brushes.Red;
combobox5.BorderBrush = Media.Brushes.Red;
combobox7.BorderBrush = Media.Brushes.Red;
How can I get the same look and feel across all the OS versions of Windows?
The following solution worked in my case. Thanks to Fe De for pointing me in the right direction.
1. Add the following to App.xaml file
2. Override the controls base styles as follows:
<ResourceDictionary Source="/PresentationFramework.Aero,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml" />
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
Related
I just realized that deriving from default style fails in my WPF app and I have no idea, why. Actually it works, but only due to "Hot reload". So I have:
<Style TargetType="ComboBox" x:Key="TestStyle" BasedOn="{StaticResource {x:Type ComboBox}}"/>
<Style TargetType="ComboBox">
<Setter Property="Width" Value="100"/>
</Style>
in resource dictionary, and:
<ComboBox Style="{StaticResource TestStyle}">
<ComboBoxItem>test</ComboBoxItem>
<ComboBoxItem>I want to cry with blood</ComboBoxItem>
</ComboBox>
in my control. When I start app I see following:
And when I remove BasedOn="{StaticResource {x:Type ComboBox}}" and add it again, I have correct view:
What can be a reason of such behavior? Seems like WPF bug, but I don't think this is possible
To find correct style you need to define it before "TestStyle"
<Style TargetType="ComboBox">
<Setter Property="Width" Value="100"/>
</Style>
<Style TargetType="ComboBox" x:Key="TestStyle" BasedOn="{StaticResource {x:Type ComboBox}}"/>
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.
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.
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.
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>