前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >(03).NET MAUI实战 基础控件

(03).NET MAUI实战 基础控件

作者头像
JusterZhu
发布2022-12-07 20:31:57
1.5K0
发布2022-12-07 20:31:57
举报
文章被收录于专栏:JusterZhu

1.概要

本章将继续介绍.NET MAUI中的常用基础控件,让刚刚接触MAUI的小伙伴有写基础的认识,心里有底开发起来将得心应手。下面将列出一些常用的基础控件:

控件名

中文名称

说明

Button

按钮

与WPF中的基础用法无太大变化

CheckBox

单选框

与WPF中的基础用法无太大变化

ListView

列表

类似WPF中列表控件“ListBox”

ImageButton

图片按钮

WPF中没有该控件,通常需要开发者手动实现,MAUI中已经包含在基础控件中。

Entry

输入框

类似WPF中的输入框控件“TextBox”

TableView

选项卡

类似WPF中"TabControl"

DisplayAlert

消息框

类似WPF中“MessageBox”

2.详细内容

(1)Button

xaml语法:

代码语言:javascript
复制
<Button Text="我是Btn" WidthRequest="200" HeightRequest="50" Command="{Binding OkCommand}" CommandParameter="{Binding}"/>
(2)CheckBox

uncheck状态

check状态

xaml语法:

代码语言:javascript
复制
<CheckBox IsChecked="True"/>
(3)ListView

xaml语法1:

代码语言:javascript
复制
<ListView ItemsSource="{Binding Temps}" HeightRequest="500" WidthRequest="300"/>

xaml语法2:

代码语言:javascript
复制
        <ListView HeightRequest="500" WidthRequest="300">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Label Text="我是listview item1" TextColor="Red"></Label>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
(4)ImageButton

xaml语法:

代码语言:javascript
复制
<ImageButton Source="/img/1.jpg" WidthRequest="200" HeightRequest="50" Command="{Binding OkCommand}" CommandParameter="{Binding}"/>
(5)Entry

xaml语法:

代码语言:javascript
复制
<Entry Text="我是输入框" WidthRequest="100" HeightRequest="50"/>
(6) TableView

xaml语法:

代码语言:javascript
复制
        <TableView HasUnevenRows="True">
            <TableView.Root>
                <TableSection TextColor="Red" Title="Tab1">
                    //Cell里也可以放其他内容
                    <TextCell TextColor="Red" Text="Item1"></TextCell>
                    <TextCell TextColor="Red" Text="Item2" IsEnabled="False"></TextCell>
                </TableSection>
                <TableSection TextColor="Blue" Title="Tab2">
                    <TextCell TextColor="Blue" Text="Item1"></TextCell>
                    <TextCell TextColor="Blue" Text="Item2"  Detail="test">
                        <TextCell.ContextActions>
                            <MenuItem Text="More"></MenuItem>
                            <MenuItem Text="Delete"></MenuItem>
                        </TextCell.ContextActions>
                    </TextCell>
                </TableSection>
            </TableView.Root>
        </TableView>

(6) DisplayAlert

C#语法:

代码语言:javascript
复制
DisplayAlert("新消息","新年快乐","ok");
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-06-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 JusterZhu 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.概要
  • 2.详细内容
    • (1)Button
      • (2)CheckBox
        • (3)ListView
          • (4)ImageButton
            • (5)Entry
              • (6) TableView
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档