views:

713

answers:

1

I am making a simple display grid that derives from ListView, and uses GridView. I want to create it in its own assembly, so i thought of using a CustomControl library and making my ListView there. the problem i have is that when i use the line in the static constructor

DefaultStyleKeyProperty.OverrideMetadata(typeof(ExtendedGridView), new FrameworkPropertyMetadata(typeof(ExtendedGridView)));

I still get the default style for listview. I have a Style defined in the generic.xaml file with the key set etc.. but it never gets instantiated. (I have checked by using snoop and also by putting a converter in it which never gets called)

I have tried doing a similar control but deriving from TextBox and that works fine. the text box's control template gets overridden.

Is there some peculiarity about listview that means i cant override its style in a custom control type fashion?

other things i have tried:

I can override the style in a calling assembly. so as a last resort i can do that.

I thought the issue might have something to do with the order that static constructors are called. i.e. Parent class's static constructor is called after the derived class's static constructor, so i tried using a static property and calling the overide metadata line in the normal constructor of my derived class, thereby ensuring it would get called last, but no joy there either.

help...

+1  A: 

Does this help?

Kent

Kent Boogaart
Thanks Kent,thats the heart of the issue. When applying a new view to the ListView (as is done when i was replacing the default view with a GridView) it overrides the style of the listview. Deriving from GridView and overriding the DefaultStyleKey property sorted it out. Winner!
Aran Mulholland
+1, solved my problem
viky