如何自定义UWP上的xamarin表单应用程序的MasterDetailPage?

时间:2017-06-28 20:12:47

标签: c# xamarin uwp xamarin.forms prism

我正在使用xamaring表单构建一个应用程序,但我不能在UWP中更改母版页的标题,它在android上工作正常但不是uwp。

以下是截图:

enter image description here

我想要做的是改变"菜单"的颜色。杆

这是XAML代码:

   <MasterDetailPage.Master>
        <ContentPage Title="Menu" BackgroundColor="Red">

            <StackLayout Orientation="Vertical">
                <StackLayout BackgroundColor="#e74c3c" HeightRequest="60">
                    <Label Text="SomeText"
                       FontSize="20"
                       VerticalOptions="CenterAndExpand"
                       TextColor="White"
                       HorizontalOptions="Center" />

                </StackLayout>


                <ListView x:Name="NavigationListView"
                  RowHeight="60"
                  SeparatorVisibility="None"
                  BackgroundColor="#e8e8e8"
                  ItemSelected="NavigationListView_ItemSelected">

                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout VerticalOptions="FillAndExpand"
                                     Orientation="Horizontal"
                                     Padding="20,10,0,10"
                                     Spacing="20">

                                    <Image Source="{Binding Icon}"
                                   WidthRequest="40"
                                   HeightRequest="40"
                                   VerticalOptions="Center"/>

                                    <Label Text="{Binding Title}"
                                   FontSize="Medium"
                                   VerticalOptions="Center"
                                   TextColor="Black"/>

                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </ContentPage>
</MasterDetailPage.Master>

<MasterDetailPage.Detail>
    <Views:MainPage />
</MasterDetailPage.Detail>

2 个答案:

答案 0 :(得分:2)

实际上,&#34;菜单&#34;的颜色你提到的BarBackgroundColor吧。因此,您可以为BarBackgroundColor实例设置NavigationPage

<MasterDetailPage.Detail>
  <NavigationPage BarBackgroundColor="PowderBlue">
    <x:Arguments>
      <pages:MasterDetailPageHomeDetail />
    </x:Arguments>
  </NavigationPage>
</MasterDetailPage.Detail>

enter image description here

答案 1 :(得分:0)

为了使我能够正常工作,出于某种原因,我不得不将其设置在隐藏的代码中:

if (Device.RuntimePlatform == Device.UWP) {
    BarBackgroundColor = Colour.LighterGray;
    BarTextColor = Colour.DarkGray;
}