none
Question on applying Style from a Resource Directory RRS feed

  • Question

  • Given:

    This is the project Folder Heirarchy:

    • Root Folder
      • App.Xaml
      • Window1.Xaml
      • Style Folder
        • ExpressionDark.Xaml
        • MergedDicts.xaml
        • Other styles
      • Windows Folder
        • Window2.xaml

    App.Xaml has this content:

    <Application.Resources> <ResourceDictionary Source="Style/MergedDicts.xaml"></ResourceDictionary> </Application.Resources>

    MergedDictionaries has this:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ExpressionDark.xaml"></ResourceDictionary> (Other styles follow here but unimportant to problem....) </ResourceDictionary.MergedDictionaries> </ResourceDictionary>

    Problem:

    Window 1 in the root folder finds the ExpressionDark Style no problem, but Window 2 in the "Windows" folder does not... How does one point to a style for a Window not picking up the App.Xaml directions? And shouldn't the App.Xaml have been sufficient for this?


    Javaman
    Friday, June 11, 2010 2:13 PM

Answers

All replies

  • Instead of using short path in MergeDictionary use the full qualified path like below which might be helpfull in your case.

    <Application.Resources> <ResourceDictionary Source=""/YourApplicationName;component/Style/MergedDicts.xaml"></ResourceDictionary> </Application.Resources>

    Also try to use full path for ExpressionDark.xaml

     


    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, June 11, 2010 5:35 PM
  • Hi Mr.Javaman,

    What is the platform you use? There is a known issue about ResourceDictionary.MergedDictionaries if you use Visual Studio 2010. Please refer to this blog about this issue:  http://blogs.windowsclient.net/rob_relyea/archive/2010/04/26/my-staticresource-reference-worked-differently-with-wpf-4-rc-than-it-does-with-wpf-4-rtm.aspx 

    There is a workaround for this issue, declare an empty style for an element in MergedDicts.xaml:

     <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="ExpressionDark.xaml">
    
       <Style TargetType="Window"/>
    
      </ResourceDictionary>
     </ResourceDictionary.MergedDictionaries>

    The similar thread: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9dce725c-6581-4b07-8644-b837c754e76c

    Sincerely,

    Bob Bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, June 15, 2010 5:58 AM
    Moderator
  • Use by this way it would not be a problem now ,

     

     

    <ResourceDictionary Source="Style Folder\ExpressionDark.xaml"/>

    Tuesday, June 15, 2010 6:45 AM