【发布时间】:2015-08-24 20:47:26
【问题描述】:
我想要实现的有点像这样
其中“某些视图”是一些自定义内容(页面或内容视图),它是固定的且永不更改(如状态栏),并且页面会通过正常导航(通过 NavigationPage)而更改。
我已经有类似的工作,但每次用户导航时都会重新创建“某些视图”,因为每个页面都源自包含“某些视图”的基本页面。
public sealed class RootPage : ExtendedMasterDetailPage
{
public RootPage()
{
// 30%
DrawerWidth = .3f;
Master = new MenuPage();
Detail = new NavigationPage(new HomePage());
}
}
public abstract class MasterPage : ContentPage
{
private readonly Grid _root;
private View _content;
// Subclasses set this property to add their content
public View Detail
{
get { return _content; }
set
{
if (_content != null)
_root.Children.Remove(_content);
_content = value;
if (_content != null)
_root.Children.Add(_content, left: 0, top: 1);
OnPropertyChanged();
}
}
protected MasterPage()
{
_root = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
RowDefinitions =
{
new RowDefinition {Height = new GridLength(60, GridUnitType.Absolute)},
new RowDefinition {Height = new GridLength(1, GridUnitType.Star)},
},
RowSpacing = 0
};
// BuildStatusBar() creates the "static" content that is placed above the page
_root.Children.Add(BuildStatusBar(), left: 0, top: 0);
Content = _root;
}
}
public sealed class HomePage : MasterPage
{
public HomePage()
{
// Build content
Detail = ...
}
}
在this blog post,作者做了一些与我类似的事情,但在 XAML 中,他似乎每次都重新加载他的内容;而我希望只有内容页面发生变化,并且标题“某些视图”保持在那里。
我相信我需要一些自定义渲染器,最好的文档似乎是this swipe to refresh custom renderer。但是我不知道如何将它应用到我的场景中。
【问题讨论】:
标签: android xamarin.forms