Hi Guys,
Last year i have created a project of Xamarin forms in VS 2015 and i have wrote global styles in APP.xaml page they were working perfectly and and published also. Recently i have installed VS 2017 global styles of same project are not working at all.
How to solve the issue?
Ahh... I think its because your use of OnPlatform
is obsolete (old syntax). If you've gone to VS2017 then your Xamarin plugin is also probably up to date, and maybe even the Xamarin.Forms version you're using now probably also got updated, right?
Notice the new syntax
<!--#region Layout and spacing--> <OnPlatform x:Key="WindowPadding" x:TypeArguments="Thickness"> <On Platform="Android" Value="10, 0, 10, 0" /> <On Platform="WinPhone" Value="10, 0, 10, 0" /> <On Platform="iOS" Value="20, 0, 20, 0" /> </OnPlatform> <!--#endregion Layout and spacing-->
See https://forums.xamarin.com/discussion/comment/337733/#Comment_337733
Try
<Style x:Key="MyTitleLabel" TargetType="Label"> <Setter Property="FontSize"> <Setter.Value> <OnPlatform x:TypeArguments="x:Double" > <On Platform="Android" > <OnIdiom x:TypeArguments="x:Double" Tablet="25" Phone="25" /> </On> <On Platform="iOS" > <OnIdiom x:TypeArguments="x:Double" Tablet="25" Phone="25" /> </On> </OnPlatform> </Setter.Value> </Setter> </Style>
Answers
@DarshanJS - Post your app.xaml and app.xaml.cs (or the relevant bits thereof), plus an example of where you consume one of the global styles.
No reason they shouldn't be working. I think its lesson 104 on my series that talks about styles - if it helps.
http://redpillxamarin.com/2018/03/12/2018-101-vs2017-new-solution/
Code in app.xaml
usage of styles in other pages for label
Hi,
Thanks for the suggestion , i am not creating new project i am getting issue in old project which i was created in VS 2015
@DarshanJS - I do mine in C# currently, rather than XAML, but from a quick look nothing looks obviously wrong in what you posted above. Is Intellisense highlighting anything, or are there any warnings when you build? Is NuGet warning about any consolidation being possible?
I hate to ask this, but since upgrading to VS2017, have you deleted your bin and obj folders? Also, if you check your version control history, has anything been changed since the upgrade?
I've never used
OnIdiom
in my styles. Just for a test, do more vanilla styles work? Just really simple ones where you set color and size and nothing else. I'm just looking to narrow down if its all styles, or justOnIdiom
in styles.Is Intellisense highlighting anything?
Yes it is highlighting for "OnIdiom.Phone" saying that "The attachable property 'Phone' was not found in the type on OnIdiom
have you deleted your bin and obj folders?
No, i didn't deleted anything and also we are maintaining projects in TFS
Sure i will check by removing OnIdiom and try with simple styles
[Deleted]
Ahh... I think its because your use of

OnPlatform
is obsolete (old syntax). If you've gone to VS2017 then your Xamarin plugin is also probably up to date, and maybe even the Xamarin.Forms version you're using now probably also got updated, right?Documentation
Notice the new syntax
No it should be OnIdiom.Phone
Thing is if i define same style code in every page under ResourceDictionary it is working properly, only it is not fetching from App.Xaml i am facing strange issue.
See https://forums.xamarin.com/discussion/comment/337733/#Comment_337733
Try
@JohnHardman :
@ClintStLaurent :
Thanks guys you both saved my day. Sometimes Xamarin will give crazy issues (other than this issue) . Thanks for everything.
This code is simple and worked for me