Pre loader

How to access colors of selected theme?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

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?

  • You must to post comments
2
0

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

  • You must to post comments
1
0

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

  • You must to post comments
1
0

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.

  • David Adams
    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 to post comments
Showing 3 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies