开发者

How to replace a ResourceDictionary of a 3rd Party UserControl (in this case PivotViewer)

开发者 https://www.devze.com 2023-01-16 14:10 出处:网络
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 in

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() {
ba开发者_Python百科se.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);

}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号