Xamarin XAML語言教程基本檢視ContentViewg構架範圍框架

大學霸發表於2017-07-10

Xamarin XAML語言教程基本檢視ContentViewg構架範圍框架

ContentView檢視基本上有三個作用,下面依次介紹。

1)範圍框架:ContentView檢視可以構建一個範圍框架,用來約束其中的子元素。

【示例14-1ContentViewScopeFrame】以下將使用ContentView來構建一個範圍框架,以此來約束其子元素。程式碼如下:


  • <?xml version="1.0" encoding="utf-8" ?>
  • <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
  •              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  •              xmlns:local="clr-namespace:ContentViewScopeFrame"
  •              x:Class="ContentViewScopeFrame.MainPage">
  •   <ContentView BackgroundColor="#B3EE3A"
  •                WidthRequest="300"
  •                HeightRequest="300"
  •                HorizontalOptions="Center"
  •                VerticalOptions="Center">
  •     <Label Text="Hello,Xamarin.Forms"
  •            FontAttributes="Bold"
  •            FontSize="18"
  •            HorizontalOptions="End"
  •            VerticalOptions="End"/>
  •   </ContentView>
  • </ContentPage>


在此程式碼中,我們將ContentView檢視作為了範圍框架,Label只可以在此框架中進行佈局。此時執行程式,會看到如圖14.8~14.9所示的效果。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29597077/viewspace-2141824/,如需轉載,請註明出處,否則將追究法律責任。

相關文章