Xaml 如何创建可用于所有xamarin表单页面的页脚?
我正在创建一个应用程序,其中我希望页脚对于所有xaml页面都是通用的。我尝试了此链接上给出的解决方案 但是它显示了部分类bcoz的错误,我在继承类时使用xamarin-xaml-formpagePageToInherit。如果我只使用page(仅.cs文件),则没有错误Xaml 如何创建可用于所有xamarin表单页面的页脚?,xaml,xamarin,xamarin.forms,footer,Xaml,Xamarin,Xamarin.forms,Footer,我正在创建一个应用程序,其中我希望页脚对于所有xaml页面都是通用的。我尝试了此链接上给出的解决方案 但是它显示了部分类bcoz的错误,我在继承类时使用xamarin-xaml-formpagePageToInherit。如果我只使用page(仅.cs文件),则没有错误 public partial class TodoList : PageToInherit { public TodoList() { InitializeComponent();
public partial class TodoList : PageToInherit
{
public TodoList()
{
InitializeComponent();
this.Title = "TodoList page";
Button button = new Button();
button.Text = "BUTTON 1";
MainStackLayout.Children.Add(button);
Content = MainStackLayout;
}
}
我想你可以去看看 创建一个控制模板
<?xml version="1.0" encoding="utf-8" ?>
<Application
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Mobile.App">
<Application.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="MainPageTemplate">
<StackLayout>
<Label Text="Header Content" FontSize="24" />
<ContentPresenter />
</StackLayout>
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
对于那些仍在寻找的人
用于创建可重用的xaml视图
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="xxx.FooterView">
<ContentView.Content>
<RelativeLayout VerticalOptions="End" HorizontalOptions="Fill" HeightRequest="42" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}">
<Label HeightRequest="42" VerticalTextAlignment="Center" Text="Copyright © 2017. All rights reserved." HorizontalTextAlignment="Center" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}" />
</RelativeLayout>
</ContentView.Content>
</ContentView>
并像任何控件一样在页面中使用它
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="xxx.Page1" xmlns:local="clr-namespace:xxx;assembly=xxx" >
<local:FooterView VerticalOptions="End" HeightRequest="45"/>
//other views and layouts
</ContentPage>
//其他视图和布局
希望有帮助。假设在控制模板中我有四张图像,在图像上单击“希望导航到另一个页面”,我应该在哪里编写代码来处理App.cs或内容页面中的单击事件?我不知道。。。我认为,就像你绑定到HeadingText一样,我认为你可以绑定到命令。
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="xxx.FooterView">
<ContentView.Content>
<RelativeLayout VerticalOptions="End" HorizontalOptions="Fill" HeightRequest="42" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}">
<Label HeightRequest="42" VerticalTextAlignment="Center" Text="Copyright © 2017. All rights reserved." HorizontalTextAlignment="Center" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}" />
</RelativeLayout>
</ContentView.Content>
</ContentView>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="xxx.Page1" xmlns:local="clr-namespace:xxx;assembly=xxx" >
<local:FooterView VerticalOptions="End" HeightRequest="45"/>
//other views and layouts
</ContentPage>