c# - Xamarin.Forms 预览器 : An Exception occurred while rendering the control

标签 c# xaml xamarin styles

我是 Xamarin 的新手。我想了解 <Style>标签。当我开始在 App.xaml 上添加标签时遇到问题文件,警告消息出现。我不知道我犯了什么错误。希望你们能帮我解决这个问题。先谢谢你们了。

错误信息

enter image description here

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="TravelRecordApp.App">
    <Application.Resources>
        <!-- Application resource dictionary -->
        <ResourceDictionary>
            <Color x:Key="blueColor">#1E90FF</Color>
            <Color x:Key="whiteColor">#FFFFFF</Color>
            <Style>
                <Setter Property="BackgroundColor" Value="{StaticResource blueColor}" />
                <Setter Property="TextColor" Value="{StaticResource whiteColor}"/>
            </Style>
        </ResourceDictionary>

    </Application.Resources>
</Application>

最佳答案

Style 标签必须始终指定TargetType。因此,例如,如果您的样式以标签为目标,则您必须将代码更改为:

<Style TargetType="Label">
    <Setter Property="BackgroundColor" Value="{StaticResource blueColor}" />
    <Setter Property="TextColor" Value="{StaticResource whiteColor}"/>
</Style>

顺便说一句,Xamarin.Forms 预览器令人头疼。即使您修复了错误消息,您收到的错误消息也可能不会消失。我必须进行彻底的清理和重建,然后打开另一个页面的预览器,关闭它并再次打开我想要的页面,然后它才会显示任何内容。

你最好不要使用它。

关于c# - Xamarin.Forms 预览器 : An Exception occurred while rendering the control,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49647562/

相关文章:

c# - 如何查看谁使用了我的网络服务

C# - 在运行时加载 xaml 文件

c# - uwp 动态创建 xaml 或新页面

c# - 无法将 ObservableCollection 绑定(bind)到 DataGrid

xamarin - 如何在 xamarin 表单中隐藏 ListView 中的滚动条

c# - 在 xamarin ios 中预加载数据库

c# - DataGrid 方法 DataSource 未找到

c# - 我最终采用了什么设计模式?

c# - 使用 DataMatrix 代码作为键盘输入

c# - 将 azure 存储客户端库与 xamarin 结合使用