Application.Resources StaticResource not found for key

PaulDistonPaulDiston USUniversity ✭✭✭✭
edited January 2015 in Xamarin.Forms

Hi,

I am trying to define a Style for a custom control I have created in the Application.Resources section of my App.xaml.cs file. However the page that references this file raises an exception (StaticResource not found for key).

The sample here :-

https://github.com/xamarin/xamarin-forms-samples

Doesn't use a Key or a Custom Control for it's Application.Resources so I am not exactly sure how to get this working.

Is there any more comprehensive examples available or any pointers as to how to get this working?

Update: The same Style defined in the Page's Resources section, works successfully.

Thanks

Paul Diston

Posts

  • JMarcusJMarcus USMember ✭✭✭

    You have to use a DynamicResource for global styles.

  • PaulDistonPaulDiston USUniversity ✭✭✭✭

    @JMarcus Thanks for that pointer, however I don't seem to be able to get it working. Do you have any examples or code snippets for global styles applied to custom controls?

  • HowardBakerHowardBaker USMember

    @PaulDiston Thanks for the find!! This saved me a lot of time.

  • @PaulDiston can you post a small example of how you got this working? This has been giving me trouble for some time. Thanks!!

  • laygrlaygr MXMember, University

    You saved me, thanks.

  • @PaulDiston Thanks, you saved me some time and searching

  • @PaulDiston one more thanks!

    Does it work with StaticResource or you've used DynamicResource as @JMarcus noted before?

  • @PaulDiston I think you've just saved me hours of frustration. I must have accidentally clobbered that InitializeComponent method call at some point, because I know it was there a few days ago. Thank you!!

    @MikeGringauz I'm using it with an (admittedly very simple) StaticResource, and so far so good...

  • JoeHealyJoeHealy USUniversity ✭✭

    @pauldiston ++ to whatever brownie point system they have here. Much appreciate with the InitializeComponent tip...

  • elefpelefp GRMember ✭✭

    @PaulDiston Thanks a lot ! This InitializeComponent tip is mentioned nowhere ! Of course the samples contain it, but who pays that detailed attention when he believes the code from old App.cs is just a copy paste? Thanks again ! I'm searching about it over an hour now.

  • BrianHondeBrianHonde USMember

    Thank you, was about to pull my hair out.

  • SamuelRuleSamuelRule USMember

    I know this was posted a year ago but thanks @PaulDiston great fix spent ages searching for this answer

  • Dr.SlumpDr.Slump ESMember

    Ahhhh! Saved me too!

  • Cheers, awesome spot.

  • jutervojutervo USMember

    thanks! just went through xamarin university "Resources and Styles" but missed this when implementing my style and got
    "StaticResource not found for key"

  • pallavboharapallavbohara USMember ✭✭
    edited March 31

    Me too getting this error while implementing Styles in App.xaml
    StaticResource not found for key <keyForStyle>!
    And its working fine in another project!
    Does anyone have clue?
    This is my App.xaml code--
    <?xml version="1.0" encoding="utf-8" ?>

    <Application.Resources>

            <Style x:Key="styleButtonCancel"  TargetType="Button">
                <Setter Property="BackgroundColor" Value="#d3d3d3"/>
                <Setter Property="TextColor" Value="White"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>
    


    And this how i am using it in some Xaml file--

  • EmmanuelPereiraEmmanuelPereira USMember

    Saved me too, @PaulDiston!

  • zahikramerzahikramer ILMember ✭✭✭

    Saved me also @PaulDiston !
    You are the Savior ! The Messiah ! :smile:

Sign In or Register to comment.