XamarinXAML语言中如何实现模板视图TemplatedView

这篇文章给大家分享的是有关Xamarin XAML语言中如何实现模板视图TemplatedView的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、网站空间、营销软件、网站建设、柞水网站维护、网站推广。

模板视图TemplatedView

与模板页面相对的是TemplatedView,它被称为模板视图,它的功能和模板页面类似,也是用来显示控件模板的,只不过比模板页面更加灵活。TemplatedView提供ControlTemplate属性,实现对控件模板的关联,从而展现对应的界面。

【示例14-6:TemplatedViewDemo】以下将使用模板视图显示控件模板,并实现模板的切换。具体的操作步骤如下:

(1)打开App.xaml文件,编写代码,实现在应用程序级别中构建控件模板,代码如下:

  • <?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="TemplatedViewDemo.App">

  •   <Application.Resources>

  • <ResourceDictionary>

  • <!--构建控件模板-->

  •       <ControlTemplate x:Key="ChineseTemplate">

  •         <StackLayout>

  •           <StackLayout VerticalOptions="End">

  •             <BoxView Color="Aqua" />

  •           </StackLayout>

  •           <StackLayout Spacing="35"

  •             VerticalOptions="CenterAndExpand"  >

  •             <Frame OutlineColor="Accent">

  •               <StackLayout Spacing="20"

  •                            VerticalOptions="CenterAndExpand"

  •                            HorizontalOptions="Center">

  •                 <Label Text="山居秋暝"

  •                        FontSize="30"

  •                        FontAttributes="Bold"

  •                        HorizontalOptions="Center"/>

  •                 <Label Text="空山新雨后,天气晚来秋。"

  •                        FontSize="18"/>

  •                 <Label Text="明月松间照,清泉石上流。"

  •                        FontSize="18"/>

  •                 <Label Text="竹喧归浣女,莲动下渔舟。"

  •                        FontSize="18"/>

  •                 <Label Text="随意春芳歇,王孙自可留。"

  •                        FontSize="18"/>

  •               </StackLayout>

  •             </Frame>

  •             <Button Command="{TemplateBinding Parent. CommandEnglish}"

  •                       Text="Enter English Template" />

  •           </StackLayout>

  •         </StackLayout>

  •       </ControlTemplate>

  • <!--构建控件模板-->

  •       <ControlTemplate x:Key="EnglishTemplate">

  •         <StackLayout>

  •           <StackLayout VerticalOptions="End">

  •             <BoxView Color="Green" />

  •           </StackLayout>

  •           <StackLayout Spacing="35"

  •                        VerticalOptions="CenterAndExpand"  >

  •             <Frame OutlineColor="Accent">

  •               <Label Text="your life only lasts for a few decades, so be sure that you don\'t leave any regrets. laugh or cry as you like, and it‘s meaningless to oppress yourself."

  •                      FontAttributes="Bold"

  •                      FontSize="18"/>

  •             </Frame>

  •             <Button Command="{TemplateBinding Parent.CommandChinese}"

  •                     Text="Enter Chinese Template" />

  •           </StackLayout>

  •         </StackLayout>

  •       </ControlTemplate>

  •     </ResourceDictionary>

  •   </Application.Resources>

  • </Application>

在此代码中,我们构建了两个控件模板,一个为ChineseTemplate控件模板,另一为EnglishTemplate控件模板。

感谢各位的阅读!关于“Xamarin XAML语言中如何实现模板视图TemplatedView”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

本文名称:XamarinXAML语言中如何实现模板视图TemplatedView
文章位置:https://www.cdcxhl.com/article16/ijdggg.html

成都网站建设公司_创新互联,为您提供动态网站做网站品牌网站制作静态网站ChatGPT网页设计公司

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设