我尝试使用 css 为我的页面设置样式,但我遇到了这个异常
你调用的对象是空的
主页.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="XRetailMobile.Views.MainPage"
xmlns:local="clr-namespace:XRetailMobile.Views.ContentViews"
NavigationPage.HasNavigationBar="False">
<ContentPage.Resources>
<StyleSheet Source="/Styles/style.css"/>
</ContentPage.Resources>
<ContentPage.Content>
<Grid HorizontalOptions="Fill" VerticalOptions="Fill">
<local:ProductBackToolbar StyleClass="toolbarStyle" VerticalOptions="Start">
</local:ProductBackToolbar>
</Grid>
</ContentPage.Content>
</ContentPage>
ProductBackToolbar.xaml(contentview)
<ContentView.Content>
<StackLayout HorizontalOptions="Fill" Orientation="Horizontal">
<Image Source="back" HeightRequest="35" VerticalOptions="Center" WidthRequest="35" HorizontalOptions="StartAndExpand"></Image>
<Image Source="share" HeightRequest="35" VerticalOptions="Center" WidthRequest="35" HorizontalOptions="End"></Image>
<Image Source="shoppingbag" HeightRequest="35" WidthRequest="35" VerticalOptions="Center" HorizontalOptions="End"></Image>
</StackLayout>
</ContentView.Content>
style.css 位于 Style 文件夹,其构建动作为 EmbeddedResources
^contentpage {
background-color: greenyellow;
}
.toolbarStyle {
background-color: blue;
margin: 20px;
padding:20px;
}
如果我评论边距和填充它工作正常有什么问题?