首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >自定义TitleView在两侧显示小的白色边框

自定义TitleView在两侧显示小的白色边框
EN

Stack Overflow用户
提问于 2019-05-10 02:41:04
回答 4查看 572关注 0票数 0

在下面的截图中,我的应用程序显示了一个标题栏,左右两侧都有一个白色的小边框。如何在设置自定义TitleView时去掉这个边框?在下面的例子中,红色框应该从屏幕的边缘延伸到另一个边缘,但您可以在两侧看到小的白色边框。

在这里,我设置了NavigationPage。

代码语言:javascript
复制
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。

代码语言:javascript
复制
<?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>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2019-05-10 04:46:08

似乎导航栏有一个默认的填充设置(尽管我在任何地方都找不到文档),并且我找不到一种方法来更改它(不使用自定义渲染器)。

但是,如果您要查找的只是获得所需颜色的整个条形图,则可以按如下方式设置页面的BarBackgroundColor属性:

代码语言:javascript
复制
protected override void OnAppearing()
{
    base.OnAppearing();
    ((NavigationPage)App.Current.MainPage).BarBackgroundColor = Color.Red;
}

票数 2
EN

Stack Overflow用户

发布于 2019-05-10 15:38:44

我建议您不要在NavigationPage.TitleView中添加BoxView,只需在App.xaml.cs中设置BarBackgroundColor,如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>

代码语言:javascript
复制
<!--<NavigationPage.TitleView>
    <BoxView BackgroundColor="Red" VerticalOptions="CenterAndExpand" />
</NavigationPage.TitleView>-->
<ContentPage.Content>
    <StackLayout Orientation="Vertical">
        <Entry Placeholder="Username" />
    </StackLayout>
</ContentPage.Content>

代码语言:javascript
复制
 public App()
    {
        InitializeComponent();

        MainPage = new NavigationPage(new MainPage()) { BarBackgroundColor=Color.Red};

    }

票数 1
EN

Stack Overflow用户

发布于 2020-05-27 23:03:29

这救了我!在App.xaml中添加ot

在ResourceDictionary下

代码语言:javascript
复制
<ResourceDictionary>
    <!--Global Styles-->
    <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="Red"/>
            <Setter Property="BarTextColor" Value="White"/>
    </Style>
</ResourceDictionary>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56065699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档