C# xamarin.forms如何在标题栏中显示视图
如何在MasterDetailView的标题栏中放置视图? 我希望尽可能多地使用xaml 我有一个MasterDetailView,它显示母版页和详细页。 详细信息页面随后显示了各种内容页,这些内容页会根据用户的操作进行更改 我想要一个静态标题视图,在这里我可以向用户显示各种统计信息 我的MasterDetailView.xamlC# xamarin.forms如何在标题栏中显示视图,c#,xaml,navigation,xamarin.forms,master-detail,C#,Xaml,Navigation,Xamarin.forms,Master Detail,如何在MasterDetailView的标题栏中放置视图? 我希望尽可能多地使用xaml 我有一个MasterDetailView,它显示母版页和详细页。 详细信息页面随后显示了各种内容页,这些内容页会根据用户的操作进行更改 我想要一个静态标题视图,在这里我可以向用户显示各种统计信息 我的MasterDetailView.xaml <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Views.MasterDetailView"
IsGestureEnabled="True"
MasterBehavior="Popover"
Title="Master Detail View">
<MasterDetailPage.Master>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
</MasterDetailPage.Detail>
</MasterDetailPage>
<?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:views="clr-namespace:MyApp.Views"
x:Class="MyApp.Views.DetailView"
Title="Detail View">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Detail View Options" Icon="options_dots.png" Order="Primary"
Command="{Binding OptionsCommand}" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
如果不扩展XF并编写自定义渲染器,则无法将框的标题视图设置为,但可以将图像设置为页面标题(如果页面包含在使用
NavigationPage.TitleIconProperty的NavigationPage中)
var page=new Page1View();
NavigationPage.SetIconTitle(第页,“foo.png”);
<?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:views="clr-namespace:MyApp.Views"
x:Class="MyApp.Views.DetailView"
Title="Detail View">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Detail View Options" Icon="options_dots.png" Order="Primary"
Command="{Binding OptionsCommand}" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:MyApp.Views"
x:Class="MyApp.Views.TitleBarView">
<ContentView.Content>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Item1}"/>
<Button Text="TitleBar Options" Command="{Binding OptionsCommand}"/>
</StackLayout>
</ContentView.Content>
</ContentView>
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:MyApp.Views"
x:Class="MyApp.Views.Page1View">
<ContentView.Content>
<StackLayout Orientation="Vertical">
<Label Text="{Binding Info}"/>
<Button Text="Go To Page 2" Command="{Binding GoToPage2Command}"/>
</StackLayout >
</ContentView.Content>
</ContentView>
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:MyApp.Views"
x:Class="MyApp.Views.Page2View">
<ContentView.Content>
<StackLayout Orientation="Vertical">
<Label Text="{Binding Info}"/>
<Button Text="Go To Page 1" Command="{Binding GoToPage1Command}"/>
<Button Text="Show Popup" Command="{Binding ShowPopupCommand}"/>
</StackLayout >
</ContentView.Content>
</ContentView>
public NavigationController()
{
masterDetailView = new MasterDetailView();
masterDetailViewModel = new MasterDetailViewModel();
masterDetailView.BindingContext = masterDetailViewModel;
masterView = new MasterView();
masterViewModel = new MasterViewModel();
masterView.BindingContext = masterViewModel;
detailView = new DetailView();
detailViewModel = new DetailViewModel();
detailView.BindingContext = detailViewModel;
titleBar = new TitleBarView();
titleBarVM = new TitleBarViewModel();
titleBar.BindingContext = titleBarVM;
page1View = new Page1View();
page1ViewModel = new Page1ViewModel();
page1View.BindingContext = page1ViewModel;
page2View = new Page2View();
page2ViewModel = new Page2ViewModel();
page2View.BindingContext = page2ViewModel;
detailView.Content = new StackLayout()
{
Children = { page1View }
};
currentView = page1View;
masterDetailView.Master = masterView;
masterDetailView.MasterBehavior = MasterBehavior.Popover;
masterDetailView.Detail = new NavigationPage(detailView);
}
public void GoToPage1()
{
if (currentView != page1View)
{
StackLayout sl = (StackLayout)detailView.Content;
sl.Children.Clear();
sl.Children.Add(page1View);
}
}
public void GoToPage2()
{
if (currentView != page2View)
{
StackLayout sl = (StackLayout)detailView.Content;
sl.Children.Clear();
sl.Children.Add(page2View);
}
}