在下面的截图中,我的应用程序显示了一个标题栏,左右两侧都有一个白色的小边框。如何在设置自定义TitleView
时去掉这个边框?在下面的例子中,红色框应该从屏幕的边缘延伸到另一个边缘,但您可以在两侧看到小的白色边框。
在这里,我设置了NavigationPage。
public partial class App : Application
{
public App()
{
InitializeComponent();
ContainerRegistration.Register();
var authPage = FreshPageModelResolver.ResolvePageModel<LoginPageModel>();
var authPageNavigation = new FreshNavigationContainer(authPage, NavigationContainerNames.AuthenticationContainer);
MainPage = authPageNavigation;
}
}
下面是引用导航页面以将TitleView
内容设置为BoxView
的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"
xmlns:control="clr-namespace:WP.MobileMidstream.Device.Pages"
x:Class="WP.MobileMidstream.Device.Pages.LoginPage"
Visual="Material">
<NavigationPage.TitleView>
<BoxView BackgroundColor="Red" />
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<Entry Placeholder="Username" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
发布于 2019-05-10 04:46:08
似乎导航栏有一个默认的填充设置(尽管我在任何地方都找不到文档),并且我找不到一种方法来更改它(不使用自定义渲染器)。
但是,如果您要查找的只是获得所需颜色的整个条形图,则可以按如下方式设置页面的BarBackgroundColor属性:
protected override void OnAppearing()
{
base.OnAppearing();
((NavigationPage)App.Current.MainPage).BarBackgroundColor = Color.Red;
}
发布于 2019-05-10 15:38:44
我建议您不要在NavigationPage.TitleView中添加BoxView,只需在App.xaml.cs中设置BarBackgroundColor,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<!--<NavigationPage.TitleView>
<BoxView BackgroundColor="Red" VerticalOptions="CenterAndExpand" />
</NavigationPage.TitleView>-->
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<Entry Placeholder="Username" />
</StackLayout>
</ContentPage.Content>
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage()) { BarBackgroundColor=Color.Red};
}
发布于 2020-05-27 23:03:29
这救了我!在App.xaml中添加ot
在ResourceDictionary下
<ResourceDictionary>
<!--Global Styles-->
<Style TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="Red"/>
<Setter Property="BarTextColor" Value="White"/>
</Style>
</ResourceDictionary>
https://stackoverflow.com/questions/56065699
复制相似问题