The image below is from a Xamarin Forms application. Notice the white area between the green and red areas. I am trying to figure out where this white area is coming from? I would think the green and red would butt right next to each other.
Here is the code that produces the above. I am using a ControlTemplate which is a requirement for my design (I am using a BoxView to illustrate the issue for this question)...
Base Class - 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="WP.MobileMidstream.Device.Pages.DialogBase"
Visual="Material"
>
<ContentPage.ControlTemplate>
<ControlTemplate>
<StackLayout>
<BoxView BackgroundColor="Green" />
<ContentPresenter VerticalOptions="FillAndExpand"
BackgroundColor="Red" />
</StackLayout>
</ControlTemplate>
</ContentPage.ControlTemplate>
</ContentPage>
Base Class - Code behind - notice the Navigation bar is made to not show
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DialogBase : ContentPage
{
public DialogBase()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
}
Page being displayed that extends DialogBase
<?xml version="1.0" encoding="utf-8" ?>
<d:DialogBase xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="clr-namespace:WP.MobileMidstream.Device.Pages"
x:Class="WP.MobileMidstream.Device.Pages.AdjustmentEditPage">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</d:DialogBase>
It's the first page shown when the app loads
public partial class App : Application
{
public App()
{
InitializeComponent();
ContainerRegistration.Register();
try
{
// register main container navigation
var mainPage = FreshPageModelResolver.ResolvePageModel<AdjustmentEditPageModel>();
var mainNavigation = new FreshNavigationContainer(mainPage, NavigationContainerNames.DailyRunSheet);
mainNavigation.BarBackgroundColor = Color.FromRgb(0, 69, 140);
mainNavigation.BarTextColor = Color.White;
MainPage = mainNavigation;
}
catch (Exception ex)
{
}
}
}
You need to use:
<StackLayout Spacing="0">
<BoxView BackgroundColor="Green" />
<ContentPresenter VerticalOptions="FillAndExpand"
BackgroundColor="Red" />
</StackLayout>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.