我尝试使用CSS将样式设置为页面,但出现此异常
对象引用未设置为对象的实例
MainPage.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位于“样式”文件夹中,其构建动作为EmbeddedResources
^contentpage {
background-color: greenyellow;
}
.toolbarStyle {
background-color: blue;
margin: 20px;
padding:20px;
}
如果我评论边距并填充它就可以了 怎么了?