【发布时间】:2021-05-11 08:31:09
【问题描述】:
如何在 C# ContentPage 中访问我的 App.xaml 上的 StaticResource 模板?
这是我的代码。 App.xaml:
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" >
<Application.Resources>
<ControlTemplate x:Key="template">
...
<Label Text="{Binding lbl_title}" Grid.Row="0"/>
<!--Body -->
<ContentPresenter Grid.Row="1"/>
...
</ControlTemplate>
</Application.Resources>
</Application>
ContentPage.xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
ControlTemplate="{StaticResource template}">
<Grid x:Name="body_grid"/>
</ContentPage>
还有 ContentPage.cs:
public partial class MenuPage : ContentPage{
public MenuPage() {
lbl_title.Text = "Title"; //This throw me and ERROR
... // Grid definition
}
}
我需要访问 lbl_title 对象,而不仅仅是他的 .Text 属性,还有他的颜色、背景等...
【问题讨论】:
标签: c# xaml xamarin xamarin.forms xamarin.android