c# - this.Resources["ControlHighlightBrush"] as Brush; throwing exception -


i trying create metro app based on developing windows 8 book oreilly.

i have following code, based on blank metro template

type roottype = typeof(dependencyobject);  typeinfo roottypeinfo = typeof(dependencyobject).gettypeinfo();  list<type> classes = new list<type>();  brush highlightbrush;   public mainpage() {     this.initializecomponent();     highlightbrush = this.resources["controlhighlightbrush"] brush;     

the last line throws exception. far understand search in common folder controlhighlightbrush if not present in standardstyles.xaml file wont work?

i think thats whats happenning?

an exception of type 'system.runtime.interopservices.comexception' occurred in mscorlib.dll not handled in user code

additional information: error hresult e_fail has been returned call com component.

if there handler exception, program may safely continued.

i don't think looks in common folder resources default. resources have explicitly specified in app.xaml in mergeddictionary collection:

<application.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>              <!--                  styles define common aspects of platform , feel                 required visual studio project , item templates              -->             <resourcedictionary source="common/standardstyles.xaml"/>             <resourcedictionary source="common/customstyles.xaml"/>         </resourcedictionary.mergeddictionaries>          <!-- application-specific resources -->          <x:string x:key="appname">my app</x:string>     </resourcedictionary> </application.resources> 

so, add custom styles in file customstyles.xaml , include above.


Comments