小编P3P*_*PPP的帖子

Xamarin.Forms:如何从另一个文件加载ResourceDictionary?

我写了下面的代码,但是XamlParseException抛出了bean.("找不到关键CustomColor的StaticResource")

MyPage.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="XFApp11.MyPage">
    <ContentPage.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="CustomResource.xaml" />
            </ResourceDictionary.MergedDictionaries> 
        </ResourceDictionary>
    </ContentPage.Resources>

    <ContentPage.Content>
        <BoxView Color="{StaticResource CustomColor}" />
    </ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

CustomResource.xaml(build action = EmbeddedResource)

<?xml version="1.0" encoding="UTF-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
                    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <Color x:Key="CustomColor">#004B86</Color>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

c# xaml xamarin xamarin.forms

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

xamarin ×1

xamarin.forms ×1

xaml ×1