1

The current version of the Microsoft Live Labs PivotViewer control for SilverLight 4 has no way to style the elements of the control. Looking at the control in Reflector, I can see much of the style info is set in a ResourceDictionary in the assembly (assets/defaultcolors.xaml). What I would like to do is create my own copy of this file, then replace it at runtime on the PivotViewer control.

By subclassing the PivotViewer control and overriding OnApplyTemplate I can grab the child elements and set properties such as Background. I have not had any success Clear()'ng the MergedDictionaries and adding in my own:

public override void OnApplyTemplate() {
base.OnApplyTemplate();

/* can change things this way */
CollectionViewerView cvv = ((CollectionViewerView)((Grid)this.GetTemplateChild("PART_Container")).Children[0]);
((Grid)cvv.Content).Background = new SolidColorBrush(Colors.Black);

/* can't change things this way */
CustomDictionary gd = new CustomDictionary();
cvv.Resources.MergedDictionaries.Clear();
cvv.Resources.MergedDictionaries.Add(gd);

}

ViNull
  • 1,022
  • 8
  • 12

1 Answers1

0

I'm afraid this isn't going to work in Silverlight because it uses only Static Resources. ( Styles Don't Update )

Changing a resource dictionary only works before InitializeComponent() is called, which is called in the constructor of the PivotViewer.

I've been trying to style the PivotViewer Control too. I hope there is another way, besides searching through the Visual Tree and changing properties.

Community
  • 1
  • 1
Sorskoot
  • 10,190
  • 6
  • 55
  • 98
  • Thanks - marking this as the answer. Time to rethink the approach. The visual tree is pretty nasty for PivotViewer, trying to style it that was would be madness! – ViNull Sep 16 '10 at 13:22