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