Bug 26724 - Global style definition not working. 1.3.2 and 1.3.3 pre1
Summary: Global style definition not working. 1.3.2 and 1.3.3 pre1
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-02-04 07:21 UTC by R.Schindler
Modified: 2015-02-16 11:24 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Test application to show the style error (4.05 MB, application/x-zip-compressed)
2015-02-04 07:22 UTC, R.Schindler

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description R.Schindler 2015-02-04 07:21:03 UTC
When I add a style to the global Application.ResourceDictionary the style is not getting applied to the controls.

See in attached project.

Uncomment the second style assigment and you can see that it works.
Comment 1 R.Schindler 2015-02-04 07:22:41 UTC
Created attachment 9635 [details]
Test application to show the style error
Comment 2 Stephane Delcroix 2015-02-04 08:21:43 UTC
you're misusing StyleId.

There are 3 ways to achieve what you want:

1/ define an implicit style, that will be applied to all Labels by default:


    			Application.Current.Resources.Add("LabelStyle", labelStyle);

(a style in a resource dictionary without a key will be treated as implicit style

2/ reference the style though a DynamicResource

			var style = (Style)Application.Current.Resources["LabelStyle"];
			label.Style = style;
			label.SetDynamicResource (Label.StyleProperty, "LabelStyle");

3/ or reference the resource just like you do
			var style = (Style)Application.Current.Resources["LabelStyle"];
			label.Style = style;
or in XAML
			<Label Style={StaticResource LabelStyle} .../>
Comment 3 R.Schindler 2015-02-04 08:24:58 UTC
In this documentation there is nothing that says this: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/styles/

Thanks for your help
Comment 4 David Laundav 2015-02-16 11:24:10 UTC
Could the documentation be updated? It is stated nowhere that Global Styles should be resolved like below:

3/ or reference the resource just like you do
            var style = (Style)Application.Current.Resources["LabelStyle"];
            label.Style = style;

Doing so resolved my NullPointerException as well.