locked
how to access Resources file in App.xaml? RRS feed

  • Question

  • Hi All,

    I have a Resources.resx file under Properties folder in my app and the content is accessible from a window as shown.

    statusMessage = Properties.Resources.NoPowerError;

    I get the below exception if I tried to do the same from App.xaml file.

    Error 13 'System.Collections.IDictionary' does not contain a definition for 'Resources' and no extension method 'Resources' accepting a first argument of type 'System.Collections.IDictionary' could be found (are you missing a using directive or an assembly reference?) 

    Is it possible to access the resource file from App.xaml, if possible any code help is appreciated.

    Thanks,

    Bharat.

    Tuesday, June 19, 2012 12:18 PM

Answers

  • Hi ykbharat,

    Please follow below steps to do so.

    # Target the Acess Modifer option in .resx to Public.

    # Register the namespace in App.xaml like this:   xmlns:r="clr-namespace:WpfApplication21.Properties"

    # Access the resource within this manner: x:Static r:Resources._2

    Hope it helps,


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by noorbakhsh Friday, June 22, 2012 2:20 PM
    • Marked as answer by Kee Poppy Tuesday, June 26, 2012 3:25 AM
    Friday, June 22, 2012 8:31 AM

All replies

  • this could help solving your problem.
    Tuesday, June 19, 2012 1:01 PM
  • Hi,

    I tried adding the complete resource file path in App.xaml.cs as said above. but lost with namespace error.

    can you please explain what need to be done.

    Thanks,

    Bharat.

    Tuesday, June 19, 2012 4:32 PM
  • Hi ykbharat,

    Please follow below steps to do so.

    # Target the Acess Modifer option in .resx to Public.

    # Register the namespace in App.xaml like this:   xmlns:r="clr-namespace:WpfApplication21.Properties"

    # Access the resource within this manner: x:Static r:Resources._2

    Hope it helps,


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by noorbakhsh Friday, June 22, 2012 2:20 PM
    • Marked as answer by Kee Poppy Tuesday, June 26, 2012 3:25 AM
    Friday, June 22, 2012 8:31 AM