11.1Xamarin一点点:View

StackLayout

线性排列一系列元素,属性有Orientation元素方向,默认为vertical

Grid

属性有RowDefinitions,ColumnDefinitions

RowDefinitions("*,auto,auto,*")

Table,Button

实例

xaml

<ContentPage.Content>
        <Grid RowDefinitions="*,auto,auto,*">
            <Label Text="{Binding CountDisplay}"/>
            <Label Grid.Row="1"
                FontSize="Large"
                Text="{Binding CountDisplay}"
                VerticalOptions="Center" 
                HorizontalOptions="Center" />
            <Button x:Name="ButtonClick"
                Text="Click me"
                Grid.Row="2"
                HorizontalOptions="Center"
                VerticalOptions="Center"
                Clicked="ButtonClick_Clicked"/>
        </Grid>
    </ContentPage.Content>

c#

public Page1()
        {
            InitializeComponent();
            BindingContext = this;
        }

        int count = 0;
        string countDisplay = "Click me";
        public string CountDisplay
        {
            get => countDisplay;
            set
            {
                if (countDisplay == value) return ;
                countDisplay = value;
                OnPropertyChanged();

            }
        }

        public void ButtonClick_Clicked(object sender, EventArgs e)
        {
            count++;
            CountDisplay = $"You have clicked {count} time(s)";
        }
posted @ 2021-11-02 00:53  fristzzz  阅读(22)  评论(0)    收藏  举报