views:

30

answers:

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);

}

A: 

I'm afraid this isn't going to work in Silverlight because it uses only Static Resources. ( http://stackoverflow.com/questions/2699982/styles-dont-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.

Sorskoot
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