只需检查下面的图像。我想更改图像上标记区域的颜色。该图片是使用开发的UWP应用程序的屏幕截图,xamarin表单跨平台项目(PCL)。 我正在使用MasterDetail页面导航。我想定制Xamarin MasterDetail(Xamarin跨平台项目)
现在颜色变为按我的第一要求。
源代码
1. MasterDetailsPage.Xaml
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GST.Views.MasterDetailsPage"
Title="Stock Manager"
MasterBehavior="SplitOnPortrait"
BackgroundColor="#0063b1"
xmlns:pages="clr-namespace:GST.Views;assembly=GST">
<MasterDetailPage.Master >
<pages:MasterDetailsPageMaster x:Name="MasterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage >
<x:Arguments>
<pages:GST_Home />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
2. MasterDetailsPage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPage : MasterDetailPage
{
public MasterDetailsPage()
{
InitializeComponent();
MasterPage.ListView.ItemSelected += ListView_ItemSelected;
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MasterDetailsPageMenuItem;
if (item == null)
return;
var page = (Page)Activator.CreateInstance(item.TargetType);
Detail.Title = item.Title;
IsPresented = false;
Detail.Navigation.PushAsync(page);
MasterPage.ListView.SelectedItem = null;
}
}
}
3. MasterDetailsPageDetail.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="GST.Views.MasterDetailsPageDetail"
BackgroundColor="{StaticResource Key=background-color}"
Title="Master GST Title Detailed" >
<StackLayout Padding="10">
<Label Text="This is a detail page. To get the 'triple' line icon on each platform add a icon to each platform and update the 'Master' page with an Icon that references it."/>
</StackLayout>
</ContentPage>
4.MasterDetailsPageDetail.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPageDetail : ContentPage
{
public MasterDetailsPageDetail()
{
InitializeComponent();
// NavigationPage.SetHasBackButton(this, false);
// NavigationPage.SetHasNavigationBar(this, false);
}
}
}
5. MasterDetailsPageMaster.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="GST.Views.MasterDetailsPageMaster"
Title="Home">
<StackLayout>
<ListView x:Name="ListViewMenuItems"
SeparatorVisibility="None"
HasUnevenRows="true"
ItemsSource="{Binding MenuItems}">
<ListView.Header>
<Grid BackgroundColor="#03A9F4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="80"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Label
Grid.Column="1"
Grid.Row="2"
Text="AppName"
Style="{DynamicResource SubtitleStyle}"/>
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="15,10" HorizontalOptions="FillAndExpand">
<Label VerticalOptions="FillAndExpand"
VerticalTextAlignment="Center"
Text="{Binding Title}"
FontSize="24"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
6.MasterDetailsPageMaster.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MasterDetailsPageMaster : ContentPage
{
public ListView ListView => ListViewMenuItems;
public MasterDetailsPageMaster()
{
InitializeComponent();
BindingContext = new ViewModels.MasterDetailsPageMasterViewModel();
}
}
}
7.MasterDetailsPageMenuItem.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GST.Views
{
public class MasterDetailsPageMenuItem
{
public MasterDetailsPageMenuItem()
{
TargetType = typeof(MasterDetailsPageDetail);
}
public int Id { get; set; }
public string Title { get; set; }
public Type TargetType { get; set; }
}
}
个
8.GST_Home.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"
NavigationPage.HasNavigationBar="False"
Title="Home Dash"
x:Class="GST.Views.GST_Home">
<StackLayout Padding="10">
<Label Text="This is a detail page. To get the 'triple' line icon on each platform add a icon to each platform and update the 'Master' page with an Icon that references it."/>
</StackLayout>
</ContentPage>
9.GST_Home.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GST.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class GST_Home : ContentPage
{
public GST_Home()
{
InitializeComponent();
}
}
}
如果你想完整的源代码,请参阅我的代码被上载谷歌驱动器:https://drive.google.com/file/d/0B2XtD2dQvEhzb1NnNGdydG91S0k/view?usp=sharing
你尝试过什么呢? –
是啊!我已将导航栏颜色更改为无花果上显示为深蓝色。 –
我的意思是关于你问的另外两个问题,你是否尝试过任何代码?或者'XAML'中的任何更改都不适合你? –