我想要达到的目标有点像这样
其中"某些观点"是一些固定且永远不会更改的自定义内容(页面或内容视图)(如状态栏),页面将通过常规导航(通过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。但是我无法弄清楚如何将它应用到我的场景中。
答案 0 :(得分:0)
我认为你无法在Xamarin.Forms中实现。
您可以使用动画更改其中内容视图的内容,但这不是正确的做法。 回顾硬件密钥是不可能的(或太多的努力)。