Xamarin.Forms样式预览颜色不显示

Xamarin.Forms样式预览颜色不显示,xamarin,xamarin.forms,xamarin.android,Xamarin,Xamarin.forms,Xamarin.android,在这种情况下,DynamicSource的颜色预览不会显示 我期待着: 上面的内容来自另一个示例项目,我正试图复制一个行为 相反,我有这样的东西: SimpleEmailEntry.xaml: <?xml version="1.0" encoding="UTF-8" ?> <ContentView     x:Class="MyApp.Views.LoginForms.SimpleEmailEntry"     x

在这种情况下,DynamicSource的颜色预览不会显示

我期待着:

上面的内容来自另一个示例项目,我正试图复制一个行为

相反,我有这样的东西:

SimpleEmailEntry.xaml:

<?xml version="1.0" encoding="UTF-8" ?>
<ContentView
    x:Class="MyApp.Views.LoginForms.SimpleEmailEntry"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:border="clr-namespace:Syncfusion.XForms.Border;assembly=Syncfusion.Core.XForms"
    xmlns:control="clr-namespace:MyApp.Controls"
    xmlns:converter="clr-namespace:MyApp.Converters">

    <ContentView.Resources>
        <ResourceDictionary>
            <converter:StringToBooleanConverter x:Key="StringToBooleanConverter" />
            <converter:ErrorValidationColorConverter x:Key="ErrorValidationColorConverter" PageVariantParameter="1" />
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </ContentView.Resources>

    <ContentView.Content>
        <StackLayout>
            <border:SfBorder
                BackgroundColor="{DynamicResource Gray-White}"
                BorderColor="{Binding Path=IsFocused, Source={x:Reference EmailEntry}, Converter={x:StaticResource ErrorValidationColorConverter}, ConverterParameter={x:Reference EmailEntry}}"
                Style="{StaticResource SfBorderStyle}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <control:BorderlessEntry
                        x:Name="EmailEntry"
                        Placeholder="Email" Keyboard="Email"
                        PlaceholderColor="{DynamicResource Gray-700}"
                        Style="{StaticResource EntryStyle}"
                        Text="{Binding Email}"
                        TextColor="{DynamicResource Gray-900}" />
                    

                    <Label
                        Margin="15,0"
                        FontFamily="{StaticResource FontIcons}"
                        FontSize="18"
                        HorizontalOptions="EndAndExpand"
                        HorizontalTextAlignment="End"
                        IsVisible="{Binding Path=IsVisible, Source={x:Reference ValidationLabel}}"
                        Text="&#xe707;"
                        TextColor="{DynamicResource Red}"
                        VerticalOptions="Center" />


                </Grid>
            </border:SfBorder>

            <Label
                x:Name="ValidationLabel"
                Margin="15,-5,0,0"
                FontSize="12"
                IsVisible="{Binding Path=IsFocused, Source={x:Reference EmailEntry}, Converter={StaticResource StringToBooleanConverter}, ConverterParameter={x:Reference EmailEntry}}"
                Text="Please enter the valid e-mail"
                TextColor="{DynamicResource Red}"
                VerticalOptions="FillAndExpand" />

        </StackLayout>
    </ContentView.Content>
</ContentView>

    
        
            
            
            
                
            
        
    
    
        
            
                
                    
                        
                        
                    
                    
                    
                    
                
            
            
        
    
App.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="http://prismlibrary.com"
             x:Class="MyApp.App"
             xmlns:themes = "clr-namespace:MyApp.Themes;assembly=MyApp">

    <Application.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <themes:LightTheme />
            </ResourceDictionary.MergedDictionaries >
        </ResourceDictionary>

    </Application.Resources>
</prism:PrismApplication>

    
        
            
                
            
        
    
LightTheme.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
    x:Class="MyApp.Themes.LightTheme"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <Color x:Key="PrimaryColor">#f54e5e</Color>
    <Color x:Key="PrimaryDarkColor">#d0424f</Color>
    <Color x:Key="PrimaryDarkenColor">#ab3641</Color>
    <Color x:Key="PrimaryLighterColor">#edcacd</Color>
    <Color x:Key="PrimaryGradient">#e83f94</Color>
    <Color x:Key="PrimaryLight">#ffe8f4</Color>
    <Color x:Key="SecondaryGradient">#7644ad</Color>
    <Color x:Key="Secondary">#d54381</Color>
    <Color x:Key="Green">#7ed321</Color>
    <Color x:Key="Red">#ff4a4a</Color>
    <Color x:Key="Orange">#ff844a</Color>
    <Color x:Key="Blue">#4acaff</Color>
    <Color x:Key="HyperLink">#567cd7</Color>

    <Color x:Key="Gray-100">#f6f7f8</Color>
    <Color x:Key="Gray-200">#ebecef</Color>
    <Color x:Key="Gray-300">#ced2d9</Color>
    <Color x:Key="Gray-400">#b2b8c2</Color>
    <Color x:Key="Gray-500">#959eac</Color>
    <Color x:Key="Gray-600">#788396</Color>
    <Color x:Key="Gray-700">#606a7b</Color>
    <Color x:Key="Gray-800">#4a515e</Color>
    <Color x:Key="Gray-900">#333942</Color>
    <Color x:Key="Gray-Black">#000000</Color>
    <Color x:Key="Gray-White">#ffffff</Color>

    <OnPlatform x:Key="FontIcons" x:TypeArguments="x:String">
        <OnPlatform.Platforms>
            <On Platform="Android" Value="UIFontIcons.ttf#UIFontIcons" />
            <On Platform="iOS" Value="UIFontIcons" />
            <On Platform="UWP" Value="Assets/UIFontIcons.ttf#UIFontIcons" />
        </OnPlatform.Platforms>
    </OnPlatform>

    <OnPlatform x:Key="Montserrat-SemiBold" x:TypeArguments="x:String">
        <OnPlatform.Platforms>
            <On Platform="Android" Value="Montserrat-SemiBold.ttf#Montserrat-SemiBold" />
            <On Platform="iOS" Value="Montserrat-SemiBold" />
            <On Platform="UWP" Value="Assets/Montserrat-SemiBold.ttf#Montserrat-SemiBold" />
        </OnPlatform.Platforms>
    </OnPlatform>

    <OnPlatform x:Key="Montserrat-Regular" x:TypeArguments="x:String">
        <OnPlatform.Platforms>
            <On Platform="Android" Value="Montserrat-Regular.ttf#Montserrat-Regular" />
            <On Platform="iOS" Value="Montserrat-Regular" />
            <On Platform="UWP" Value="Assets/Montserrat-Regular.ttf#Montserrat-Regular" />
        </OnPlatform.Platforms>
    </OnPlatform>

    <OnPlatform x:Key="Montserrat-Medium" x:TypeArguments="x:String">
        <OnPlatform.Platforms>
            <On Platform="Android" Value="Montserrat-Medium.ttf#Montserrat-Medium" />
            <On Platform="iOS" Value="Montserrat-Medium" />
            <On Platform="UWP" Value="Assets/Montserrat-Medium.ttf#Montserrat-Medium" />
        </OnPlatform.Platforms>
    </OnPlatform>

    <OnPlatform x:Key="Montserrat-Bold" x:TypeArguments="x:String">
        <OnPlatform.Platforms>
            <On Platform="Android" Value="Montserrat-Bold.ttf#Montserrat-Bold" />
            <On Platform="iOS" Value="Montserrat-Bold" />
            <On Platform="UWP" Value="Assets/Montserrat-Bold.ttf#Montserrat-Bold" />
        </OnPlatform.Platforms>
    </OnPlatform>

</ResourceDictionary>

#f54e5e
#d0424f
#ab3641
#edcacd
#e83f94
#ffe8f4
#7644ad
#d54381
#7ed321
#ff4a4a
#ff844a
#4acaff
#567cd7
#f6f7f8
#ebecef
#ced2d9
#b2b8c2
#959eac
    #788396
#606a7b
#4a515e
    #333942
    #000000
#ffffff
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    

谢谢你们

我认为你用错了资源字典的方法。检查以下步骤

  • 在项目中创建
    LightTheme.xaml

  • 假设
    LightTheme.xaml
    在同一程序集中。如果要使用来自其他程序集的资源字典,可以将其添加到ResourceDictionary的MergedDictionaries属性中

    SimpleEmailEntry.xaml
    中设置资源字典:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
          x:Class="ResourceDictionaryDemo.HomePage">
    
      <ResourceDictionary>           
         <ResourceDictionary Source="LightTheme.xaml" />          
     </ResourceDictionary>
    
    </ContentPage>
    
    
    
  • 使用颜色和键

    <Label
         BackgroundColor="{DynamicResource Key=Gray-Black}"
         FontAttributes="Bold"
         HorizontalOptions="Center"
         Text="ListView with a DataTemplateSelector" />
    
    
    

  • 我认为你用错了资源字典的方法。检查以下步骤

  • 在项目中创建
    LightTheme.xaml

  • 假设
    LightTheme.xaml
    在同一程序集中。如果要使用来自其他程序集的资源字典,可以将其添加到ResourceDictionary的MergedDictionaries属性中

    SimpleEmailEntry.xaml
    中设置资源字典:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
          x:Class="ResourceDictionaryDemo.HomePage">
    
      <ResourceDictionary>           
         <ResourceDictionary Source="LightTheme.xaml" />          
     </ResourceDictionary>
    
    </ContentPage>
    
    
    
  • 使用颜色和键

    <Label
         BackgroundColor="{DynamicResource Key=Gray-Black}"
         FontAttributes="Bold"
         HorizontalOptions="Center"
         Text="ListView with a DataTemplateSelector" />