我想做与这个问题相同的事情,但是对于 .NET MAUI:所有 WPF 窗口中的页眉和页脚相同 https://stackoverflow.com/questions/20113405/same-header-footer-in-all-wpf-windows
所有窗口的页眉和页脚都是相同的。
我找到了一种更好的方法来使用控件模板来做到这一点。
PageLayout.xaml 文件:
<ContentPage ...>
<ContentPage.Resources>
<ControlTemplate x:Key="PageLayoutTemplate">
<Grid RowDefinitions="Auto,*,Auto">
<!--Header-->
<Grid>
<!--header content-->
</Grid>
<!--Content-->
<ContentPresenter Grid.Row="1"/>
<!--Footer-->
<Grid Grid.Row="2">
<!--footer content-->
</Grid>
</Grid>
</ControlTemplate>
</ContentPage.Resources>
</ContentPage>
SubView.xaml 文件:
<PageLayout ...
ControlTemplate="{StaticResource PageLayoutTemplate"}>
<Grid>
<!--Main content-->
</Grid>
</PageLayout>
为什么这样更好:
- 后面没有代码
- 由于模板绑定,绑定变得更加容易
- 可以轻松添加备用模板
参考:https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/controltemplate?view=net-maui-7.0 https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/controltemplate?view=net-maui-7.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)