I have a RichTextBox with a vertical scrollbar via VerticalScrollBarVisibility="Visible". Styling the Scrollbar itself works fine as I would expect it with the following inside <RichTextBox.Resources>
<Style TargetType="{x:Type ScrollBar}">
<Setter Property="Margin" Value="2"/>
<Setter Property="Background" Value="{DynamicResource steam2004ControlLight}"/>
<Setter Property="BorderBrush" Value="{DynamicResource steam2004BorderBright}"/>
</Style>
Trying to style the Thumb and Repeatbutton in a similar way however proved to be ineffective.
<Style TargetType="{x:Type Thumb}">
<Setter Property="Margin" Value="2"/>
<Setter Property="Background" Value="{DynamicResource steam2004ControlLight}"/>
<Setter Property="BorderBrush" Value="{DynamicResource steam2004BorderBright}"/>
</Style>
<Style TargetType="{x:Type RepeatButton}">
<Setter Property="Margin" Value="2"/>
<Setter Property="Background" Value="{DynamicResource steam2004ControlLight}"/>
<Setter Property="BorderBrush" Value="{DynamicResource steam2004BorderBright}"/>
</Style>
Now, do note that I am only about two days into wrapping my head around WPF, so if my approach is totally busted, that's why :D
Any insight would be appreciated.
Related
I'm trying to create a simple TextBox style. I want to create a trigger to change the colors when the textbox is disabled:
<Style TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontSize" Value="{StaticResource NormalFontSize}"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontStyle" Value="Normal"/>
<Setter Property="FontFamily" Value="{StaticResource FontFamilyName}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{StaticResource listItemHighlightBackground}"/>
<Setter Property="Foreground" Value="{StaticResource disabledArrowBackground}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
When I use the trigger, the textbox disappears
What's wrong here?
Thanks
A ControlTemplate replaces the template for that control type. It looks like you're misunderstanding its usage. Before the triggers, try adding some visual objects to display, such as a border, and that will appear. Better yet, don't use a ControlTemplate at all...you only need to set a property trigger on the style, e.g:
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property = "Foreground" Value="Green"/>
</Trigger>
</Style.Triggers>
I have breaking my brain over this for a couple of hours now. I'm only trying to center my datagrid content vertical and horizontally. Every time something seems to work it gives other problems. My code currently is like the following:
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid>
<ContentPresenter HorizontalAlignment="Center" />
<ContentPresenter VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFA1A1A1"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FFA1A1A1"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="BorderThickness" Value="0"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="35"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Background" Value="#FFDDDDDD"/>
<Setter Property="Foreground" Value="#FF3E3E42"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFA1A1A1"/>
<Setter Property="Foreground" Value="#FFD1D1D1"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FFA1A1A1"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="BorderThickness" Value="0"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
With this code the text is aligned vertical and horizontally, but... There are two problems coming with this code.
1.) I can only select a row by clicking on the text. This needs to be the whole row.
2.) If I edit a column text then the vertical alignment will go from center to top. Also the textbox is only wrapped around the text.
I have tried almost every combination but it's not working. Thanks in advance!
EDIT: I got point 2 working now. If somebody knows somethings about point 1, please let me know
I have a DataGrid containing some DataGridComboBoxColumns.
I would like the comboBoxes inside those columns to have a certain style applied.
so I tried adding the following to my DataGrid's Resources:
<Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="Background" Value="{StaticResource DefaultBackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource DefaultBorderBrush}"/>
<Setter Property="Foreground" Value="{StaticResource DefaultForegroundBrush}"/>
<Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}"/>
<Setter Property="FontSize" Value="{StaticResource DefaultFontSize}"/>
<Setter Property="Padding" Value="2"/>
</Style>
does not do anything at all.
amazingly enough, if I add:
<Style x:Key="{x:Type ComboBoxItem}" TargetType="ComboBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Foreground" Value="Red"/>
</Style>
the comboBoxItems inside the same comboBoxes will get the red foreground color Correctly.
so basically, I cannot set the style of the comboBoxes inside my dataGrid, but I can set the style of the comboBoxItems inside those same comboBoxes.
quite surprising...
does anyone have a clue about what's going on here and how I can solve my problem?
thanks
What exactly is this supposed to do? x:Key="{x:Type ComboBox}"
You should not assign keys if you want styles to be applied to all controls in the subtree.
Edit: To apply the styles to the ComboBoxes you must adjust the properties DataGridComboBoxCotlumn.ElementStyle and DataGridComboBoxColumn.EditingElementStyle.
I currently use this style for my ComboBox in WPF:
<Style TargetType="ComboBox">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="#303030"/>
<Setter Property="BorderBrush" Value="#000000"/>
</Style>
How can I change it to specify the background color when the ComboBox is disabled?
(this is a follow-up to this question: WPF combobox colors)
<Style TargetType="ComboBox">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="#303030"/>
<Setter Property="BorderBrush" Value="#000000"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="#101010"/>
</Trigger>
</Style.Triggers>
</Style>
I ended up using the style used here as a base, and this did allow to set the background color when disabled:
http://msdn.microsoft.com/en-us/library/ms752094%28v=VS.85%29.aspx
I am trying to work out a style for a ComboBox that has a navy background with white text, so I want the drop down arrow to be white also (the xaml I have so far is below).
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
<Setter Property="Background" Value="{StaticResource headerBrush}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderBrush" Value="{StaticResource headerBorderBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="MinWidth" Value="100"/>
<Setter Property="Height" Value="21"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="Margin" Value="3"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
<Style x:Key="ComboBoxItemStyle" TargetType="ComboBoxItem">
<Setter Property="Background" Value="AliceBlue"/>
<Setter Property="Foreground" Value="Navy"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
</Style>
ADDED code to set the ControlTemplate?
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Path x:Name="Arrow" Fill="White"/>
</ControlTemplate>
</Setter.Value>
</Setter>
You need to edit the ControlTemplate of ComboBox and you can see a the Arrow as a Path. So change the Fill property of the Path to your desired arrow color. See sample ControlTemplate here
http://msdn.microsoft.com/en-us/library/ms752094.aspx