我有一个相当简单的 Xamarin.Forms
应用程序,带有 ContentPage
和一个 ControlTemplate
在 App.Xaml
ResourceDictionary
我正在尝试绑定(bind)到 ContentPage.Title
父 ContentPage 的属性。但是以下似乎不起作用..
内容页
<ContentPage
x:Class="Inhouse.Mobile.Pcl.Views.MoveLocationView"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
ControlTemplate="{StaticResource MainPageTemplate}"
Title="Move Location"
...
控制模板
<?xml version="1.0" encoding="utf-8" ?>
<Application
x:Class="Inhouse.Mobile.Pcl.App"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Application.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="MainPageTemplate">
<cut for Brevity ...>
<StackLayout BackgroundColor="#333333">
<Label Text="{TemplateBinding Page.Title}"></Label>
</StackLayout>
<ScrollView Grid.Row="2" >
<ContentPresenter VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />
</ScrollView>
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
我不确定我实际上应该绑定(bind)什么
即我的尝试是
<Label Text="{TemplateBinding Page.Title}"></Label>
最佳答案
我的问题是我在 StackLayout
中并且需要设置
HorizontalOptions="StartAndExpand"
这样我就可以看到它。
此外,标题
就足够了
{TemplateBinding Title}
即
<StackLayout Grid.Row="1" BackgroundColor="#333333">
<Label Text="{TemplateBinding Title}" TextColor="AliceBlue" HorizontalOptions="StartAndExpand"/>
</StackLayout>
关于xamarin - 从 ControlTemplate 绑定(bind)到 ContentPage 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45341184/