I have a WPF TextBlock control that I want to set the foreground color for based on the colors in the current SciChart theme (I want to make it the same color as, say, the axis titles). How do I access the color values for the current theme?
- David Adams asked 9 years ago
- You must login to post comments
Newsflash. This actually works
1: Declare the theme resource in your UserControl.Resources
Allowable theme resource dictionary names are BlackSteel.xaml, Electric.xaml, Oscilloscope.xaml, BrightSpark.xaml, Chrome.xaml, ExpressionDark.xaml, ExpressionLight.xaml
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Abt.Controls.SciChart.Wpf;component/Themes/BlackSteel.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources
2: Use the brushes directly as static resource
<TextBlock FontSize="20" Text="Hello Theming World!" Foreground="{StaticResource TickTextBrush}"/>
Allowable resource names are listed in the KB Article on ThemeColorProviders.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 9 years ago
- You must login to post comments
Ooo
That’s a really good question, and not one anyone has asked before.
This is what we do. Inside SciChart we setup a theme in a ResourceDictionary called a ThemeProvider. You can see an overview of ThemeProvider with the resource names of brushes in the article How to Create a Custom Theme for SciChart
Now what we do is we have created a MarkupExtension which binds to the selected theme implicitly, allowing you to select one of these brushes. e.g. this code
<TextBlock Text="Hello Theme World!" Foreground="{s:ThemeBinding Path=TickTextBrush}"/>
Would bind the current theme TickTextBrush to the foreground of the TextBlock.
However … I have no idea if this will work outside of SciChart. ThemeBinding internally looks to the ThemeManager.Theme property of the current object and as themes are set per-chart.
Maybe you will need to do something like this:
<Grid x:Name="someContainerGrid" s:ThemeManager.Theme="ExpressionDark">
<!-- somewhere lower down in your app -->
<TextBlock Text="Hello Theme World!" Foreground="{s:ThemeBinding Path=TickTextBrush}"/>
</Grid>
Just a guess. I have no idea if this works.
- Andrew Burnett-Thompson answered 9 years ago
-
I can do it in the code behind: textBlock.Foreground = chart.XAxis.TickTextBrush; Where is the property for the axis label and title color? Can't find it.
- You must login to post comments
Hi David,
You could also try getting colors from ThemeManager.ThemeProvider, which holds the color scheme used exposed via the IThemeProvider interface. ThemeManager is a static class, so you can access it.
Please let us know if you managed to get the colors,
Best regards,
Yuriy
- Guest answered 9 years ago
- You must login to post comments
Please login first to submit.