简体   繁体   中英

Xamarin styles doesn't work - xamarin.forms

my Application is always with a white screen if I use style. When I debugged I found out it doesn't leave the line

InitializeComponent();

that is in the app xaml cs

it builds, but after gets white screen forever.

this is my app xaml:

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="neoFly_Montana.App">
<Application.Resources>

    <!-- Application resource dictionary -->
    <ResourceDictionary>
        <Color x:key="BackButton">Black</Color>

        <Style x:Key="button" TargetType ="but">
            <Setter Property="BackgroundColor" Value="{StaticResource BackButton}"/>
        </Style>
    </ResourceDictionary>
</Application.Resources>

The exception:

Xamarin.Forms.Xaml.XamlParseException: Position 11:14. Type but not found in xmlns http://xamarin.com/schemas/2014/forms occurred

Help please

There is no such type but ...

Replace TargetType ="but" with TargetType="Button" , and everything should work fine.

And BTW, looking at your code, it's a good habit to adopt strict naming rules, in this way you don't mix out lower/upper casing or key names. I say this because the key of your color is pascal-case, while the button's is in lower-case. You should also use more specific keys, not just button , but I believe this was just for the example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM