I am using WPF Toolkit Area Chart control. I am not able to change background of the Area Series to any other color. It just assigns color code #FFFFA500.
My XAML code is as below
<chartingToolkit:Chart.Palette x:Uid="tt">
<datavis:ResourceDictionaryCollection>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FF3EA0C0"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FF44C8F5"/>
</Style>
</ResourceDictionary>
</datavis:ResourceDictionaryCollection>
</chartingToolkit:Chart.Palette>
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Width" Value="0"/>
<Setter Property="Height" Value="0"/>
</Style>
</chartingToolkit:Chart.LegendStyle>
<chartingToolkit:AreaSeries Background="Black" x:Name="SecondSeries" DependentValuePath="Value" IndependentValuePath="Key" IsSelectionEnabled="True">
<chartingToolkit:AreaSeries.DataPointStyle>
<Style TargetType="chartingToolkit:AreaDataPoint">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Width" Value="Auto" />
<Setter Property="Height" Value="30" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:AreaDataPoint">
<Button Name="pointButton" Content="{Binding}" Click="pointButton_Click_1" BorderThickness="1" >
<Button.Template>
<ControlTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Value}" Cursor="Hand"></TextBlock>
</StackPanel>
</ControlTemplate>
</Button.Template>
</Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</chartingToolkit:AreaSeries.DataPointStyle>
<chartingToolkit:AreaSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis Orientation="Y" FontFamily="Rockwell" Title="Expenses" FontSize="14" >
</chartingToolkit:LinearAxis>
</chartingToolkit:AreaSeries.DependentRangeAxis>
</chartingToolkit:AreaSeries>
</chartingToolkit:Chart>
Please help me out. This is driving me crazy.
The problem is that there is a Grid within the AreaSeries control Template which has a style applied to it setting the background to a LinearGradientBrush.
In order to change the background of the plot area, add this style
<Style TargetType="Grid" x:Key="plotStyle">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="Pink"/>
</Setter.Value>
</Setter>
</Style>
and use it as the Chart control's PlotAreaStyle
<chartingToolkit:Chart Background="Black" PlotAreaStyle="{StaticResource plotStyle}">
Related
I'm trying to set up a trigger that removes the padding on the listview when the scrollbar is hidden.
I put the trigger on the listview style but I'm getting inconsistent results. For example the background property in the trigger is always active no matter what the scrollbar visibility is.
I've taken a look at the MSDN for the ScrollViewer.ComputedVerticalScrollBarVisibility Property but am not having much luck figuring out what's wrong.
<ListView Grid.Row="1" Grid.Column="1" BorderBrush="{x:Null}" BorderThickness="0" ItemsSource="{Binding Tasks}" Margin="5"
ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<!-- SNIP -->
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Style>
<Style>
<Setter Property="ListView.Padding" Value="0,0,5,0"/>
<Setter Property="ListView.Background" Value="{x:Null}" />
<Style.Triggers>
<Trigger Property="ScrollViewer.ComputedVerticalScrollBarVisibility" Value="Hidden">
<Setter Property="ListView.Padding" Value="0"/>
<Setter Property="ListView.Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.Style>
</ListView>
I write an ListView style example which worked for me. I tried it.
<Style TargetType="ListView">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<ScrollViewer>
<ScrollViewer.Style>
<Style TargetType="ScrollViewer">
<Style.Triggers>
<Trigger Property="ComputedVerticalScrollBarVisibility" Value="Visible">
<Setter Property="Padding" Value="100"/>
</Trigger>
<Trigger Property="ComputedVerticalScrollBarVisibility" Value="Collapsed">
<Setter Property="Padding" Value="10"/>
</Trigger>
</Style.Triggers>
</Style>
</ScrollViewer.Style>
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I expect the following Style to affect any Border that is child of the Expander object to which this Style is applied to have a 1-pixel thick gray border. Why doesn't it work?
<Style TargetType="Expander">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Border>
<Border.Resources>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="BorderThickness" Value="1" />
</Style>
</Border.Resources>
<ContentPresenter Content="{Binding}" />
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
For two TabItems I have two Styles, both use the same ControlTemplate. Now I want styleTabB to show a yellow underline instead of green, but still using the ControlTemplate. How can I modify the Style to accomplish this?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" FontSize="16">
<Window.Resources>
<ControlTemplate x:Key="ctrlTemplate" TargetType="{x:Type TabItem}">
<Grid>
<TextBlock Name="tbTabItemHeaderText"
Text="{TemplateBinding Header}"
Grid.Column="0"
Background="Thistle"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="3,0,0,3">
<TextBlock.TextDecorations>
<TextDecorationCollection>
<TextDecoration Location="Underline"
PenThicknessUnit="Pixel"
PenOffsetUnit="Pixel"
PenOffset="2">
<TextDecoration.Pen>
<Pen Brush="Green" Thickness="4" />
</TextDecoration.Pen>
</TextDecoration>
</TextDecorationCollection>
</TextBlock.TextDecorations>
</TextBlock>
</Grid>
</ControlTemplate>
<!-- Style Tab A -->
<Style x:Key="styleTabA" TargetType="{x:Type TabItem}">
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
<!-- Style Tab B -->
<Style x:Key="styleTabB" TargetType="{x:Type TabItem}">
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
</Window.Resources>
<Grid>
<TabControl Name="tabControl">
<TabItem Name="tabItem_1" Header="--- Tab A ---" Style="{StaticResource styleTabA}"/>
<TabItem Name="tabItem_2" Header="--- Tab B ---" Style="{StaticResource styleTabB}" />
</TabControl>
</Grid>
</Window>
UPDATE
I tried the proposal of Chris W., but no underline at all is shown:
<ControlTemplate x:Key="ctrlTemplate" TargetType="{x:Type TabItem}">
...
<TextDecoration.Pen>
<Pen Brush="{TemplateBinding Tag}" Thickness="4" />
</TextDecoration.Pen>
...
</ControlTemplate>
<!--Style Tab A-->
<Style x:Key="styleTabA" TargetType="{x:Type TabItem}">
<Setter Property="Tag" Value="Green" />
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
<!--Style Tab B-->
<Style x:Key="styleTabB" TargetType="{x:Type TabItem}">
<Setter Property="Tag" Value="Yellow" />
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
You can set the style of the children within the child by targetting particular types. Here all Pen are updated with Yellow color.
<Style x:Key="styleTabB" TargetType="{x:Type TabItem}">
<Style.Resources>
<Style TargetType="{x:Type Pen}">
<Setter Property="Brush" Value="Yellow"></Setter>
</Style>
</Style.Resources>
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
#CarbineCoder is correct for most instances but for your instance you're right and the error you received from his would be expected since Pen isn't a TargetType. However if we tweak it just a little to hit the actual FrameworkElement of which TextDecorations is a property let's try this...and read the whole thing since the first snippet is just an example explanation.
<Style x:Key="styleTabB" TargetType="{x:Type TabItem}">
<Style.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextDecorations">
<Setter.Value>
<TextDecorationCollection>
<TextDecoration>
<TextDecoration.Pen>
<Pen Brush="Yellow"/>
</TextDecoration.Pen>
</TextDecoration>
</TextDecorationCollection>
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
** *Except that's not going to work because you're hoping for something that you've already provided an explicit property value for to inherit from parent, and it doesn't work that way. How about instead we bring in the handy Tag property (which I abuse all the time) to piggy back in our value and allow a way to talk to our buddy on the inside of that bugger by making some quick edits to your ControlTemplate like;
<!-- In your STYLE Template you would want to add a default setter of;
<Setter Property="Tag" Value="Green"/>
-->
<ControlTemplate x:Key="ctrlTemplate" TargetType="{x:Type TabItem}">
<Grid Margin="0,0,0,0">
<TextBlock Name="_tbTabItemHeaderText"
Text="{TemplateBinding Header}"
Grid.Column="0"
Background="Thistle"
VerticalAlignment="Center"
Margin="3,0,0,3">
<TextBlock.TextDecorations>
<TextDecorationCollection>
<TextDecoration Location="Underline"
PenThicknessUnit="Pixel"
PenOffsetUnit="Pixel"
PenOffset="2">
<TextDecoration.Pen>
<Pen Brush="{TemplateBinding Tag}" Thickness="4" />
</TextDecoration.Pen>
</TextDecoration>
</TextDecorationCollection>
</TextBlock.TextDecorations>
</TextBlock>
</Grid>
</ControlTemplate>
Now we should be able to hit like;
<!-- Style Tab A
: This guy should just keep it green IF you applied the default setter mentioned above to the STYLE template -->
<Style x:Key="styleTabA" TargetType="{x:Type TabItem}">
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
<!-- Style Tab B
: This guy should turn it Yellow -->
<Style x:Key="styleTabB" TargetType="{x:Type TabItem}">
<Setter Property="Tag" Value="Yellow"/>
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
I didn't have time to test, but it seems like this should work fine for your scenario. Hope it helps.
I made a little change on Chris W.'s solution and now it's working:
<ControlTemplate x:Key="ctrlTemplate" TargetType="{x:Type TabItem}">
...
<TextDecoration.Pen>
<!--Changed next line from <Pen Brush="{TemplateBinding Tag}" Thickness="4" /> to:-->
<Pen Brush="{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}}" Thickness="4" />
</TextDecoration.Pen>
...
</ControlTemplate>
<!--Style Tab A-->
<Style x:Key="styleTabA" TargetType="{x:Type TabItem}">
<Setter Property="Tag" Value="Green" />
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
<!--Style Tab B-->
<Style x:Key="styleTabB" TargetType="{x:Type TabItem}">
<Setter Property="Tag" Value="Yellow" />
<Setter Property="Template" Value="{StaticResource ctrlTemplate}" />
</Style>
WPF Toolkit library has Autocompletebox control.
1. How to place an icon at the left of its Textbox part?
2. How to add shadow to the borders of the suggestions popup?
Changing TextBoxStyle property does not give any results.
<!-- xmlns:extendedControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" -->
<extendedControls:AutoCompleteBox>
<extendedControls:AutoCompleteBox.TextBoxStyle>
<Style TargetType="TextBox">
<Setter Property="Padding" Value="20,0,0,0" />
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/img.png" Stretch="None" AlignmentX="Left" />
</Setter.Value>
</Setter>
</Style>
</extendedControls:AutoCompleteBox.TextBoxStyle>
</extendedControls:AutoCompleteBox>
The Autocompletebox have got a property : TextBoxStyle where you can chose the style of the textbox.
Or you can do that in the property Style like that :
<UserControl.Resources>
<Style TargetType="TextBox" x:Key="TextboxStyle2">
<Setter Property="MaxLength" Value="74" />
<Setter Property="Width" Value="300" />
</Style>
<Style TargetType="controls:AutoCompleteBox" x:Key="TextBoxStyle">
<Setter Property="TextBoxStyle" Value="{StaticResource TextboxStyle2}" />
<Setter Property="IsTextCompletionEnabled" Value="True" />
</Style>
</UserControl.Resources>
/*...*/
<controls:AutoCompleteBox Name="Titre" Style="{StaticResource TextBoxStyle}"/>
But i don't know how to add the shadow. Try the others properties. =)
Edit :
To change background, there is already some tutoriels.
how to separate the background image in wpf textbox?
Exemple :
<Style TargetType="TextBox" x:Key="TextboxStyle2">
<Setter Property="MaxLength" Value="74" />
<Setter Property="Width" Value="300" />
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="../../../Ressources/Icones/Find_5650.ico" Stretch="None" AlignmentX="Left" AlignmentY="Top" />
</Setter.Value>
</Setter>
</Style>
I have these styles defined:
<Style x:Key="ImgButton" TargetType="Button">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="Height" Value="30"></Setter>
</Style>
<Style x:Key="ImgButtonWithText" TargetType="{x:Type Button}" BasedOn="{StaticResource ImgButton}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Name="ButtonImage" Stretch="Uniform" Height="20" Width="20" Source="">
</Image>
<TextBlock Name="ButtonText" Margin="4,0" VerticalAlignment="Center" Text=""></TextBlock>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
I want to create another style, LoginButtonWithText (shown below), that is based on ImgButtonWithText, and which sets the value of the Source property of the ButtonImage control in the ImgButtonWithText style. I want to do the same with the Text property of the ButtonText textblock.
<Style x:Key="LoginButtonWithText" TargetType="{x:Type Button}" BasedOn="{StaticResource ImgButtonWithText}">
<Setter Property="ToolTip" Value="Login"></Setter>
<Setter Property="IsDefault" Value="True"></Setter>
//How do I set the Image Source value and TextBlock Text value here?
</Style>
I found this question, but it doesn't appear to be quite exactly what I'm looking for. How do I change the value of child controls from an inherited style, or am I doing it all wrong?
It seems that what I want to do is not exactly possible, but I've done the next best thing in defining an image button style to use in all styles that inherit from from ImgButtonWithText:
<Style x:Key="ImgButton" TargetType="Button">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="Height" Value="30"></Setter>
</Style>
<Style x:Key="ButtonImage" TargetType="Image">
<Setter Property="Height" Value="20"></Setter>
<Setter Property="Width" Value="20"></Setter>
<Setter Property="Stretch" Value="Uniform"></Setter>
</Style>
<Style x:Key="ButtonText" TargetType="TextBlock">
<Setter Property="Margin" Value="4,0"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
</Style>
<Style x:Key="LoginButtonWithText" TargetType="{x:Type Button}" BasedOn="{StaticResource ImgButton}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Name="ButtonImage" Style="{StaticResource ButtonImage}" Source="../Images/login.png">
</Image>
<TextBlock Name="ButtonText" Style="{StaticResource ButtonText}" Text="Let's Go"></TextBlock>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>