This is a migrated thread and some comments may be shown as answers.

Binding to Metro Theme AccentColor in code behind

2 Answers 115 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 31 Oct 2012, 01:32 AM
Is it possible to bind to the Metro Theme AccentColor in code behind?

I found it easy to do in XAML: http://www.telerik.com/help/silverlight/common-styles-appearance-colorizing-metro-theme.html
<SolidColorBrush x:Key="AccentBrush" Color="{Binding Source={StaticResource MetroColors}, Path=Palette.AccentColor}" />

Setting the color using radGrid.BorderBrush = new SolidColorBrush(MetroColors.PaletteInstance.AccentColor); does not update the radGrid's BorderBrush when the AccentColor is changed.


In code behind I'm get the exception "Cannot find a Resource with the Name/Key MetroColors [Line: 10 Position: 36]" when I try to use the following binding:
            Binding accentColor = new Binding("Palette.AccentColor");
            accentColor.Source = App.Current.Resources["MetroColors"];
            accentColor.Converter = new ColorToBrushConverter();
            radGrid.SetBinding(RadGridView.BorderBrushProperty, accentColor);

2 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 02 Nov 2012, 02:10 PM
Hello Shawn,

 It's not necessary to bind to the Metro Theme in code behind. Actually, if you want to change some properties of a specific control, based on Metro Theme, you can define a style based on the theme and change the colors in it. Check the following code snippet for reference:

<UserControl.Resources>
  <Style x:Key="s1" TargetType="telerik:RadGridView" telerik:StyleManager.BasedOn="Metro">
    <Setter Property="BorderBrush" Value="Orange"/>
    </Style>
  </UserControl.Resources>
  <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
    <telerik:RadGridView telerik:StyleManager.Theme="Metro" Style="{StaticResource s1}" ItemsSource="{Binding Collection}"/>
  </Grid>
</UserControl>


Kind regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Shawn
Top achievements
Rank 1
answered on 14 Nov 2012, 11:08 PM
Hi Yoan,

Thank you for the reply. I think this answers my question, what you're saying is it's not possible to do this in the code-behind.

Also, thank you for the XAML example.
Tags
General Discussions
Asked by
Shawn
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Shawn
Top achievements
Rank 1
Share this question
or