Xaml 如何使用合并的样式?

Xaml 如何使用合并的样式?,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,如何使用合并样式?我正在合并应用程序文件,然后我想在另一个屏幕上使用它,但我找不到样式,我怎么了 <?xml version="1.0" encoding="UTF-8"?> <ResourceDictionary xmlns=... x:Class="CodeFabric.ExpenseTracker.Mobile.Forms.Styles.EntryStyle"> <Style x:Key="highlighte

如何使用合并样式?我正在合并应用程序文件,然后我想在另一个屏幕上使用它,但我找不到样式,我怎么了

<?xml version="1.0" encoding="UTF-8"?>
<ResourceDictionary xmlns=...
                    x:Class="CodeFabric.ExpenseTracker.Mobile.Forms.Styles.EntryStyle">

    <Style x:Key="highlightedLabel" TargetType="Label">
        <Setter Property="TextColor" Value="White" />
        <Setter Property="BackgroundColor" Value="LightGreen" />
    </Style>

</ResourceDictionary>

我在这里合并:直到这里一切正常

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary MergedWith="local:EntryStyle"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

但是当我在这里使用样式时,找不到该样式。为什么?

<Label Style="{StaticResource highlightedLabel}" Text="I'm Highlighted" />

现在“MergedWith”属性已过时,请参阅

基本上,您可以将合并词典与独立的资源文件一起使用,如下所示:

<Application ...
             xmlns:local="clr-namespace:ResourceDictionaryDemo">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <local:MyResourceDictionary />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    ...
</Application>

希望有帮助。

试试这个:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <local:EntryStyle />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>


希望这有帮助。-

但是我如何在控件中使用?但我如何在控件中使用?是的,你会像使用其他资源一样使用它。以上代码将在编译时将所有资源合并到一个文件中。