Global styles which are coded in visaul studio 2015 project are not working in VS 2017

DarshanJSDarshanJS USMember ✭✭✭✭

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?

Best Answers

Answers

  • JohnHardmanJohnHardman GBUniversity mod
    edited August 2018

    @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.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    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/

  • DarshanJSDarshanJS USMember ✭✭✭✭
    edited August 2018

    @JohnHardman said:
    @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.

    Code in app.xaml

        <Application.Resources>
                <ResourceDictionary>
                    <Style x:Key="MyTitleLabel" TargetType="Label" >
                        <Setter Property="FontSize" >
                            <Setter.Value>
    
                                <OnIdiom x:TypeArguments="x:Double">
                                    <OnIdiom.Phone>
                                        <OnPlatform x:TypeArguments="x:Double" iOS="14" Android="15"  />
                                    </OnIdiom.Phone>
                                    <OnIdiom.Tablet>
                                        <OnPlatform x:TypeArguments="x:Double" iOS="21" Android="21"  />
                                    </OnIdiom.Tablet>
                                </OnIdiom>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="TextColor" Value="#000000" />
                        <Setter Property="FontAttributes" Value="None" />
    
                    </Style>
            </ResourceDictionary>
         </Application.Resources>
    

    usage of styles in other pages for label

    <Label x:Name="lblmessage" Margin="20,20,0,0"  IsVisible="False" Grid.Row="1" Text="Sorry, No results found"  HorizontalOptions="CenterAndExpand"  Style="{StaticResource MyTitleLabel}"/>
    
  • DarshanJSDarshanJS USMember ✭✭✭✭

    @ClintStLaurent said:
    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/

    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

  • JohnHardmanJohnHardman GBUniversity mod
    edited August 2018

    @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?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    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 just OnIdiom in styles.

  • DarshanJSDarshanJS USMember ✭✭✭✭

    @JohnHardman said:
    @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?

    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

  • DarshanJSDarshanJS USMember ✭✭✭✭

    @ClintStLaurent said:
    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 just OnIdiom in styles.

    Sure i will check by removing OnIdiom and try with simple styles

  • JohnHardmanJohnHardman GBUniversity mod
    edited August 2018

    [Deleted]

  • DarshanJSDarshanJS USMember ✭✭✭✭

    @JohnHardman said:
    Like I said, I don't use XAML for this, so I could be completely wrong, but should the '.' in OnIdiom.Phone be a space?

    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.

  • DarshanJSDarshanJS USMember ✭✭✭✭
    edited August 2018

    @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

            <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> 
    
Sign In or Register to comment.