I am trying to style the scrollbars in my datagrids using app.xaml (want it to be global across the app)
My code I have done is
<Style TargetType="{x:Type DataGrid}">
<Setter Property="ScrollViewer.Background" Value="LightBlue"></Setter>
<Setter Property="ScrollViewer.Foreground" Value="LightGray"></Setter>
</Style>
However, it doesn't work, is there anything I have missed?
Cheers
Try this
<Style TargetType="{x:Type DataGrid}">
<Style.Resources>
<Style TargetType="ScrollViewer">
<Setter Property="Background" Value="LightBlue"/>
<Setter Property="TextElement.Foreground" Value="LightGray"/>
</Style>
</Style.Resources>
</Style>
Note : for scrollbar change target type <Style TargetType="Scrollbar">
Related
Is it possible to define a ResourceDictionary in a Style?
For example, suppose I wanted to have two different Styles for StackPanels and in one I want all the buttons to be blue and the other I want them to be red. Is this possible?
Something like
<Style x:Key="RedButtonsPanel" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="StackPanel.Resources">
<Setter.Value>
<ResourceDictionary>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
</Style>
</ResourceDictionary>
</Setter.Value>
</Setter>
</Style>
The above code fails with an error about the Property value of a Setter cannot be null (even though it's obviously not null).
I can do something like
<ResourceDictionary x:Key="RedButtons">
<Style TargetType="{x:Type Button}">
<Setter Property="Width" Value="100" />
<Setter Property="Background" Value="Red" />
</Style>
</ResourceDictionary>
<StackPanel Resources={StaticResource RedButtons} />
However I was wondering if there was a way to merge the ResourceDictionary into the style.
Try adding the Style(s) for each TargetType to the DockPanel Style.Resources.
I did something similar with a DockPanel Style. Wanted all Buttons or Separators added to the DockPanel to get styled in a consistent manner.
Here's a sample:
<Style x:Key="DockPanelToolBarStyle" TargetType="{x:Type DockPanel}">
<Style.Resources>
<Style TargetType="Button" BasedOn="{StaticResource ButtonToolBarStyle}" />
<Style TargetType="Separator" BasedOn="{StaticResource SeparatorToolBarStyle}" />
</Style.Resources>
<Setter Property="Height" Value="45"/>
<Setter Property="Background" Value="{StaticResource ToolBarBrush}"/>
</Style>
StackPanel.Resources is not a DependencyProperty and therefore I don't believe you will be able to set that property within the style.
I have problem with FocusVisualStyle in my application.
I would like to disable it globally, but I cannot get it done. I have created 2 styles:
<Style TargetType="{x:Type Control}">
<Setter
Property="FocusVisualStyle"
Value="{x:Null}" />
</Style>
<Style TargetType="{x:Type FrameworkElement}">
<Setter
Property="FocusVisualStyle"
Value="{x:Null}" />
</Style>
And placed it at the beginning of ResourceDictionary.MergedDictionaries of my App.
Unfortunately, this is not working.
I am using MahApp.Metro and DevExpress and this might be a problem here.
Do you have any solution for that?
I'm trying to figure out how to change the style of the AvalonEdit CodeCompletion window. However, I can't figure out the right combination of xaml style target/properties to change it. The main thing I'd like to do is get rid of the border, but maybe some additional changes as well.
Here is the xaml I've tried. None of it is affecting the UI.
xmlns:ae="clr-namespace:ICSharpCode.AvalonEdit.CodeCompletion;assembly=ICSharpCode.AvalonEdit"
<Style TargetType="{x:Type ae:CompletionWindow}">
<Setter Property="WindowStyle" Value="None" />
</Style>
<Style TargetType="{x:Type ae:CompletionWindowBase}">
<Setter Property="WindowStyle" Value="None" />
</Style>
<Style TargetType="{x:Type ae:CompletionListBox}">
<Setter Property="Background" Value="Red" />
</Style>
<Style TargetType="{x:Type ae:CompletionList}">
<Setter Property="Background" Value="Orange" />
</Style>
Use this style to remove border on window:
<Style TargetType="{x:Type avalonEdit:CompletionWindow}">
<Setter Property="WindowStyle" Value="None"></Setter>
<Setter Property="ResizeMode" Value="NoResize"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
</Style>
To make the styles affect the UI, you can put them in a resource dictionary xaml and parse that with (ResourceDictionary)XamlReader.Parse(ResourcesAsXaml).
Then assign the ResourceDictionary to the Resources property of the CompletionWindow.
What is the equivalent in XAML? Make Background Red for every Label which are inside a StackPanel.
/*In CSS*/
StackPanel Label {
Background:Red
}
//XAML
<Style TargetType="Label">
<!-- Condition??? -->
<Setter Property="Background" Value="Red"/>
</Style>
You can put a default Style for Labels in a default Style for StackPanels:
<Style TargetType="StackPanel">
<Style.Resources>
<Style TargetType="Label">
<Setter Property="Background" Value="Red"/>
</Style>
</Style.Resources>
</Style>
is it possible to define resources in the style rather then using a template?
<ListView.Resources >
<Style TargetType="{x:Type ScrollBar}">
<Setter Property="Background" Value="Transparent" />
</Style>
</ListView.Resources>
How can I wrap this thing into:
<Style TargetType="{x:Type ListView}">
</Style>
?
I'm not sure I understand your question correctly... is that what you're looking for ?
<Style TargetType="{x:Type ScrollBar}">
<Style.Resources>
<Style TargetType="{x:Type ListView}">
</Style>
</Style.Resources>
<Setter Property="Background" Value="Transparent" />
</Style>