【问题标题】:How can I change the Detail Title section?如何更改详细标题部分?
【发布时间】:2019-05-18 04:15:00
【问题描述】:

我有一个 Xamarin Forms 应用程序,它支持的唯一平台是 UWP。我使用主从架构。我了解如何更改详细信息页面的标题文本,但我需要更改例如标题窗格的高度及其背景颜色。我想应该在 MySolution.UWP 项目上完成,但不知道如何处理。我什至不知道我应该改变什么,TopCommandBarArea,或者 CommandBar,或者 LayoutRoot 等等。

这是我共享项目中的一些代码:

    private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        var item = e.SelectedItem as MainMDPageMenuItem;
        if (item == null)
            return;

        item.ItemBackgroundColor = Color.FromHex("#006c89");
        if (PreviouslySelectedItem != null)
        {
            PreviouslySelectedItem.ItemBackgroundColor = Color.FromHex("#00a8d5");
        }

        var page = (Page)Activator.CreateInstance(item.TargetType);
        page.Title = item.Title;

        Detail = new NavigationPage(page);
        IsPresented = false;

        MasterPage.ListView.SelectedItem = null;

        PreviouslySelectedItem = item;
    }

【问题讨论】:

    标签: xamarin.forms uwp-xaml xamarin.uwp


    【解决方案1】:

    要更改标题栏背景颜色,请在 Xamarin Forms 项目中的 App.Xaml 中添加以下 sn-p:

     <Application.Resources>
            <ResourceDictionary>
                <Style TargetType="NavigationPage">
                    <Setter Property="BarBackgroundColor"
                            Value="Maroon"></Setter>
                    <Setter Property="BarTextColor"
                            Value="Violet"></Setter>
                </Style>
            </ResourceDictionary>
        </Application.Resources>
    

    要更改字体属性,请在您的 UWP 项目中添加以下代码 sn-p App.Xaml

    <Application.Resources>
                <ResourceDictionary>
                    <Style x:Key="TitleTextBlockStyle"
                           BasedOn="{StaticResource BaseTextBlockStyle}"
                           TargetType="TextBlock">
                        <Setter Property="FontWeight"
                                Value="SemiLight" />
                        <Setter Property="FontSize"
                                Value="36" />
                        <Setter Property="OpticalMarginAlignment"
                                Value="TrimSideBearings" />
                    </Style>
                </ResourceDictionary>
     </Application.Resources>
    

    【讨论】:

    • 谢谢,换色效果很好!但是如何设置导航栏的高度呢?
    • @DavidShochet 如果有帮助,请查看this 文章。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 2012-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多