6.在Xamarin.Forms中使用XAML代码创建页面
2015-10-22 22:57
369 查看
xaml代码的方式也是和WPF的差不多,比如写一个label
但是目前还是有个比较明显的缺点就是和代码一样,没有设计器,不能直接看到界面的预览。
下面就开始写个吧。
首先先创建一个xaml页面:
然后输入如下代码:
把App.cs文件里写一下就可以了:
效果图:
<Label Text="Hello from XAML!" IsVisible="True" XAlign="Center" TextColor="Blue" FontSize="Large" FontAttributes="Bold,Italic" />
但是目前还是有个比较明显的缺点就是和代码一样,没有设计器,不能直接看到界面的预览。
下面就开始写个吧。
首先先创建一个xaml页面:
然后输入如下代码:
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="App15.Page1"> <ContentPage.Content> <StackLayout> <StackLayout.Children> <Frame OutlineColor="Accent"> <Frame.Content> <StackLayout Orientation="Horizontal"> <StackLayout.Children> <BoxView Color="Red" /> <Label Text="Red" VerticalOptions="Center" /> </StackLayout.Children> </StackLayout> </Frame.Content> </Frame> <Frame OutlineColor="Accent"> <Frame.Content> <StackLayout Orientation="Horizontal"> <StackLayout.Children> <BoxView Color="Green" /> <Label Text="Green" VerticalOptions="Center" /> </StackLayout.Children> </StackLayout> </Frame.Content> </Frame> <Frame OutlineColor="Accent"> <Frame.Content> <StackLayout Orientation="Horizontal"> <StackLayout.Children> <BoxView Color="Blue" /> <Label Text="Blue" VerticalOptions="Center" /> </StackLayout.Children> </StackLayout> </Frame.Content> </Frame> </StackLayout.Children> </StackLayout> </ContentPage.Content> </ContentPage>
把App.cs文件里写一下就可以了:
public class App : Application { public App() { MainPage = new Page1(); } protected override void OnStart() { // Handle when your app starts } protected override void OnSleep() { // Handle when your app sleeps } protected override void OnResume() { // Handle when your app resumes } }
效果图:
相关文章推荐
- c语言中字符串的常用函数
- java初始化构造函数调用顺序
- PHP设计模式二:单例模式
- Spring AOP三种拦截方式举例详解
- c语言中字符串的输入和输出
- java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
- c语言中的字符串
- Java 线程的状态
- Yii2的深入学习--自动加载机制
- Quartz使用-入门使用(java定时任务实现)
- 谈谈 Python 程序的运行原理
- Spring注解详解
- eclipse打开出现jdk的jvm.dll加载失败
- IDEA替换myecplise中文乱码 +导入包 + svn代码同步 + maven导jar错误处理教程。(处女作-^_^-)
- python问与答常识
- 关于spring
- 三大框架整合(二)—— Spring 和 Struts2
- springmvc 之 DispatcherServlet
- Binary search algorithm in C source code
- spring中scope作用域