How can I override the AxisLabel Foreground setting within my own App.xaml resource dictionary?
I've tried this but does not work
<Style TargetType="ig:NumericAngleAxis" > <Setter Property="LabelSettings"> <Setter.Value> <ig:AxisLabelSettings Foreground="Blue" FontSize="20"/> </Setter.Value> </Setter> </Style>
Hello,
The easiest way to change the color of the label would be to set it in the LabelSettings of the axis.
<ig:NumericYAxis x:Name="yAxis" > <ig:NumericYAxis.LabelSettings> <ig:AxisLabelSettings Foreground="Red"/> </ig:NumericYAxis.LabelSettings>
In case you would like to have this styled, I can suggest two options:
1. Re-templating the Label. The label text is held by a textblock which can be styled.
<Style TargetType="{x:Type TextBlock}" x:Key="foreColorBlock"> <Setter Property="Foreground" Value="Orange"/> </Style> <ig:CategoryXAxis x:Name="xmCategoryXAxis" ItemsSource="{StaticResource CategoryData1}"> <ig:CategoryXAxis.Label> <DataTemplate> <TextBlock Style="{StaticResource foreColorBlock}" Text="{Binding Item.Category}"/> </DataTemplate> </ig:CategoryXAxis.Label>
More on Axis Label templates can be read on our website here.
2. Define a brush resource and use it as Foreground Color:
<SolidColorBrush x:Key="foregroundBrush" Color="{DynamicResource ColorDefinedByLogic}"/> <ig:CategoryXAxis.LabelSettings> <ig:AxisLabelSettings Foreground="{StaticResource foregroundBrush}"/> </ig:CategoryXAxis.LabelSettings>
Should you have any further questions, please let me know.
Sincerely,Tihomir TonevAssociate Software DeveloperInfragistics
I'm still having trouble dynamically changing the color. My situation is to change from a light theme to dark theme. I do this by removing lighttheme.xaml and adding darktheme.xaml to/from mergeddictionaries in codebehind.
In my XamDataChart control:<ig:CategoryAngleAxis.LabelSettings> <ig:AxisLabelSettings Location="InsideTop" Extent="20" FontSize="12" Foreground="{StaticResource ForegroundSolid}"/> </ig:CategoryAngleAxis.LabelSettings> </ig:CategoryAngleAxis>
In my app.xaml <SolidColorBrush x:Key="ForegroundSolid" Color="{DynamicResource IForegroundSolid}"/>
In darktheme.xaml: <Color x:Key="IForegroundSolid">Blue</Color>
In lighttheme.xaml: <Color x:Key="IForegroundSolid">Red</Color>
By design Application resources are read only, so I am not sure your dynamic color is resolving at all. Furthermore Dynamic resource are resolved in code at runtime so why don't you just add the following:
private void Button_Click(object sender, RoutedEventArgs e) { SolidColorBrush getLabelBrush = this. FindResource("currentLabelBrush") as SolidColorBrush; if (getLabelBrush.Color == Colors.Blue) { getLabelBrush.Color = Colors.Yellow; } else getLabelBrush.Color = Colors.Blue; this.Resources.Remove("currentLabelBrush"); this.Resources.Add("currentLabelBrush", getLabelBrush); }
Where "currentLabelBrush" is your current color:<Window.Resources> <SolidColorBrush x:Key="currentLabelBrush" Color="Blue"/></Window.Resources>
<ig:CategoryXAxis.LabelSettings> <ig:AxisLabelSettings Foreground="{StaticResource currentLabelBrush}"/> </ig:CategoryXAxis.LabelSettings>
In regards to this approach -
<Color x:Key="IForegroundSolid">Blue</Color>
I don't think this will work, as there is no Dependency Property involved, so even though you change the value, no one will know about it.
Alternative approach to this would be to be using MergedDictionaries.
I believe something like this should also do the trick:
ReseouceDictionary light = new ResourceDictionary() { Source = new Uri("lightTheme.xaml", UriKind.Relative) }ReseouceDictionary dark= new ResourceDictionary() { Source = new Uri("darkTheme.xaml", UriKind.Relative) }Application.Current.Resources.MergedDictionaries.Add(light);And then:
Application.Current.Resources.MergedDicitonaries.Remove(light);Application.Current.Resources.MergedDictionaries.Add(dark);Should you have any further questions, please let me know.