C# Xamarin.Forms App.xaml MergedDictionaries-静态资源查找未检测样式

C# Xamarin.Forms App.xaml MergedDictionaries-静态资源查找未检测样式,c#,xaml,xamarin,xamarin.forms,C#,Xaml,Xamarin,Xamarin.forms,我正在创建一个应用程序,稍后将转到Play Store。该应用程序组织有序,并且使用MVVM模式 在我的应用程序中-我有一个名为“Styles”的文件夹,其中包含应用程序不同元素的多种样式: 如您所见,我有一个用于浮动操作按钮的ResourceDictionary: <?xml version="1.0" encoding="utf-8" ?> <ResourceDictionary xmlns="http://xamarin

我正在创建一个应用程序,稍后将转到Play Store。该应用程序组织有序,并且使用MVVM模式

在我的应用程序中-我有一个名为“Styles”的文件夹,其中包含应用程序不同元素的多种样式:

如您所见,我有一个用于浮动操作按钮的ResourceDictionary:

<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                    xmlns:FAB="clr-namespace:Refractored.FabControl;assembly=Refractored.FabControl"
                    xmlns:rsvpapp="clr-namespace:RSVPApp"
                    x:Class="RSVPApp.Styles.FloatingActionButton">

    <Color x:Key="FAB_BlueNormalStyleColor">
        #0BA1D8
    </Color>

    <Color x:Key="FAB_BlueRippleStyleColor">
        #21B7ED
    </Color>

    <Color x:Key="FAB_BluePressedStyleColor">
        #3DCBFF
    </Color>


    <Color x:Key="FAB_RedNormalStyleColor">
        #CF0000
    </Color>

    <Color x:Key="FAB_RedRippleStyleColor">
        #ED2121
    </Color>

    <Color x:Key="FAB_RedPressedStyleColor">
        #FF3D3D
    </Color>

    
    <Color x:Key="FAB_OrangeNormalStyleColor">
        #FFA500
    </Color>

    <Color x:Key="FAB_OrangeRippleStyleColor">
        #EDA621
    </Color>

    <Color x:Key="FAB_OrangePressedStyleColor">
        #FFBB3D
    </Color>


    <Color x:Key="FAB_GreenNormalStyleColor">
        #00E500
    </Color>

    <Color x:Key="FAB_GreenRippleStyleColor">
        #69FA69
    </Color>

    <Color x:Key="FAB_GreenPressedStyleColor">
        #85FF85
    </Color>

    <!--Blue-->
    <Style x:Key="FAB_BlueRegularStyle"
           TargetType="FAB:FloatingActionButtonView">
        <Setter Property="ImageName"
                Value="ic_add_white.png" />

        <Setter Property="ColorNormal"
                Value="{StaticResource FAB_BlueNormalStyleColor}" />

        <Setter Property="ColorRipple"
                Value="{StaticResource FAB_BlueRippleStyleColor}" />

        <Setter Property="ColorPressed"
                Value="{StaticResource FAB_BluePressedStyleColor}" />

        <Setter Property="HasShadow"
                Value="True" />

        <Setter Property="IsVisible"
                Value="True" />
    </Style>

    <Style x:Key="FAB_BlueMiniStyle"
           TargetType="FAB:FloatingActionButtonView"
           BasedOn="{StaticResource FAB_BlueRegularStyle}">
        <Setter Property="Size"
                Value="Mini" />
    </Style>

    
    <!--Red-->
    <Style x:Key="FAB_RedRegularStyle"
           TargetType="FAB:FloatingActionButtonView"
           BasedOn="{StaticResource FAB_BlueRegularStyle}">
        <Setter Property="ColorNormal"
                Value="{StaticResource FAB_RedNormalStyleColor}" />

        <Setter Property="ColorRipple"
                Value="{StaticResource FAB_RedRippleStyleColor}" />

        <Setter Property="ColorPressed"
                Value="{StaticResource FAB_RedPressedStyleColor}" />
    </Style>

    <Style x:Key="FAB_RedMiniStyle"
           TargetType="FAB:FloatingActionButtonView"
           BasedOn="{StaticResource FAB_RedRegularStyle}">
        <Setter Property="Size"
                Value="Mini" />
    </Style>

    
    <!--Orange-->
    <Style x:Key="FAB_OrangeRegularStyle"
           TargetType="FAB:FloatingActionButtonView"
           BasedOn="{StaticResource FAB_BlueRegularStyle}">
        <Setter Property="ColorNormal"
                Value="{StaticResource FAB_OrangeNormalStyleColor}" />

        <Setter Property="ColorRipple"
                Value="{StaticResource FAB_OrangeRippleStyleColor}" />

        <Setter Property="ColorPressed"
                Value="{StaticResource FAB_OrangePressedStyleColor}" />
    </Style>

    <Style x:Key="FAB_OrangeMiniStyle"
           TargetType="FAB:FloatingActionButtonView"
           BasedOn="{StaticResource FAB_OrangeRegularStyle}">
        <Setter Property="Size"
                Value="Mini" />
    </Style>


    <!--Green-->
    <Style x:Key="FAB_GreenRegularStyle"
           TargetType="FAB:FloatingActionButtonView"
           BasedOn="{StaticResource FAB_BlueRegularStyle}">
        <Setter Property="ColorNormal"
                Value="{StaticResource FAB_GreenNormalStyleColor}" />

        <Setter Property="ColorRipple"
                Value="{StaticResource FAB_GreenRippleStyleColor}" />

        <Setter Property="ColorPressed"
                Value="{StaticResource FAB_GreenPressedStyleColor}" />
    </Style>

    <Style x:Key="FAB_GreenMiniStyle"
           TargetType="FAB:FloatingActionButtonView"
           BasedOn="{StaticResource FAB_GreenRegularStyle}">
        <Setter Property="Size"
                Value="Mini" />
    </Style>
</ResourceDictionary>

#0BA1D8
#21B7ED
#3DCBFF
#CF0000
#ED2121
#FF3D3D
#FFA500
#EDA621
#FFBB3D
#00E500
#69FA69
#85FF85
现在-我想将所有资源字典合并到我的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"
             xmlns:styles="clr-namespace:RSVPApp.Styles"
             x:Class="RSVPApp.App">
    <!--
        Define global resources and styles here, that apply to all pages in your app.
    -->
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <styles:FloatingActionButton />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
            <Color x:Key="Primary">#2196F3</Color>
            <Style TargetType="Button">
                <Setter Property="TextColor" Value="White"></Setter>
                <Setter Property="VisualStateManager.VisualStateGroups">
                    <VisualStateGroupList>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal">
                                <VisualState.Setters>
                                    <Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
                                </VisualState.Setters>
                            </VisualState>
                            <VisualState x:Name="Disabled">
                                <VisualState.Setters>
                                    <Setter Property="BackgroundColor" Value="#332196F3" />
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateGroupList>
                </Setter>
            </Style>
        </ResourceDictionary>        
    </Application.Resources>
</Application>
 

#2196F3
如您所见,在顶部我声明了一个合并字典属性,在内部我有相应的资源字典

在我的一个页面中,我决定测试是否检测到样式:

    <fab:FloatingActionButtonView Style="{StaticResource FAB_BlueRegularStyle}"/>

每当我构建应用程序时,它都会立即崩溃,因为它无法检测样式

也许我做错了什么?我不能完全肯定。我正在寻找解决办法


谢谢,

在我的项目中,我使用如下CSS文件。然后可以使用CSS设置很多(不是全部)属性

以下是有关该主题的更多信息:

下面是远未完成的情况:

此文件名为Main.css,位于“css”目录中:

* {
    background-color: black;
    color: white;
}

body{
}

.StackLayout
{
    padding: 0;
}

Button {
    background-color: darkslateblue;
    color: white;
    font-size: 10;
    margin: 1;
    border-radius: 5;
}

Button.Delete {
    background-color: red;
    color: white;
}

Editor {
    color: black;
    background-color: white;
    min-height: 300;
}

Entry {
    color: white;
    background-color: black;
}

Label {
    color: white;
    background-color: black;
}

TabbedPage {
    BarBackgroundColor: black;
    color: white;
}

.WordContainer {
}

StackLayout.TitleViewBack {
    background-color: #2296f3;
}

Label.TitleView {
    font-size: 30;
    background-color: #2296f3;
    color: wheat;
}

.ToolbarTitle {
    text-align: center;
    color: red;
}
在我的App.xaml中,我使用以下命令。样式表现在可用于所有xaml表单

<?xml version="1.0" encoding="utf-8" ?>
<tgb:TxfApplication
    xmlns:forms="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:tgb="clr-namespace:TGB.Xamarin.Forms;assembly=TGB.Xamarin.Forms"
    xmlns:views="clr-namespace:eTabber.Views"
    xmlns:css="clr-namespace:XamlCSS;assembly=XamlCSS"
    x:Class="eTabber.App">
    <tgb:TxfApplication.Resources>
        <StyleSheet Source="/css/Main.css" />

        <views:TitleView x:Key="MainTitleView"/>

        <Style TargetType="ContentPage" x:Key="TitleView">
            <Setter Property="NavigationPage.TitleView" Value="{StaticResource MainTitleView}"/>
        </Style>
    </tgb:TxfApplication.Resources>
</tgb:TxfApplication>

我创建了一个测试并试图解决您的问题。我找不到严重的问题。我还对指定图像源的行进行了注释。这是我的结果,我发现了关于你的问题

思想 起初,不是


...
用这个,


...
你从中获益

测试结果 这是我从模拟器和编译器得到的结果。

潜在错误 也许您在
.csproj
文件中声明了错误,因为在下图中,我看不到箭头来查看xaml.cs文件。在
style\u FloatingActionButton.xaml文件中,您指向
FloatingActionButton
类声明。你真的有这个文件吗?

也许重新创建资源字典并检查文件属性。应该是这样的。

请添加您收到的异常的确切信息,好吗?我在一个空白项目中复制了您的代码,并修改了一些琐碎的东西(我更改了按钮的FloatingActionButtonView,并相应地更改了样式),并且样式在我这边被正确读取。。。