当前位置: 首页 > news >正文

Avalonia笔记2 -数据集合类控件

学习笔记:

1.    DataGrid 笔记1中已经记录;

2. ItemsControl 

属性:

ItemsSource:数据源

ItemsControl.ItemTemplate:单项数据模板,内部使用<DataTemplate>

示例:

<ItemsControl Grid.Row="4" ItemsSource="{Binding ItemModels}" ><ItemsControl.ItemTemplate><DataTemplate><Grid><Grid.RowDefinitions ><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions><TextBlock Text="{Binding LastName}"></TextBlock><TextBlock Text="{Binding FirstName}"></TextBlock></Grid></DataTemplate></ItemsControl.ItemTemplate>
</ItemsControl>
    public List<Person> ItemModels { get; set; } = new List<Person>();public MainWindowViewModel(){ItemModels.Add(new Person("eew", "dsjuoj"));ItemModels.Add(new Person("Ne22323ids", "dsjuoj"));ItemModels.Add(new Person("rrrr", "dsjuoj"));}

 水平方向可以根据父元素尺寸自动调整,但垂直方向不可以。

3. ItemsRepeater   具有数据模板和布局模板

需要引用nuget包

<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.0.9" />

属性:

ItemsSource

ItemsRepeater.ItemTemplate

ItemsRepeater.Layout:设置布局的方向,默认垂直

// 该标签内必须设置StackLayout
<ItemsRepeater.Layout><StackLayout Spacing="40" Orientation="Horizontal" />
</ItemsRepeater.Layout>

该标签内必须设置StackLayout。

<ItemsRepeater Grid.Row="5" Grid.RowSpan="3" ItemsSource="{Binding ItemModels}"><ItemsRepeater.Layout><StackLayout Orientation="Horizontal"></StackLayout></ItemsRepeater.Layout><ItemsRepeater.ItemTemplate><DataTemplate><Border Margin="0,10,0,0" CornerRadius="5" BorderBrush="Blue" BorderThickness="1" Padding="5"><StackPanel Orientation="Horizontal"><TextBlock Text="{Binding FirstName}"></TextBlock><TextBlock Margin="5 0" Text="{Binding LastName}"></TextBlock></StackPanel></Border></DataTemplate></ItemsRepeater.ItemTemplate>
</ItemsRepeater>

                     

 4.  ListBox

属性:

Items:数据项集合。只有get属性

SelectedIndex:下标

SelectedItem:单选

SelectedItems: 多选

Selection:一个ISelectionModel对象,具有各种方法来跟踪多个选定项目

SelectionMode:选择模式,值为:Single(单选模式)、Multiple(多选模式)、Toggle(所选项目可以切换,若不启用,则需要用“shift/ctrl”切换)、AlwaysSelected(始终被选择)

ScrollViewer.Horizontal:水平滚动条的可见性,值:Disabled(默认)、Auto、Hidden、Visible。

ScrollViewer.Vertical:垂直滚动条的可见性,值:Disabled(默认)、Auto、Hidden、Visible。

示例:

<ListBox Grid.Row="5" x:Name="animals">
 animals.ItemsSource = new string[] { "cat", "dog", "bird", "tiger", "duck", "chicken" }.OrderBy(x=>x);

 

 5. ComboBox  下拉框

属性:

Items:数据项集合,只读

SelectedIndex

SelectedItem

SelectedItems

AutoScrollToSelectedItem:是否自动滚动到所选择的项

IsDropDownOpen:是否打开下拉

MaxDropDownHeight:下拉最大高度,这是列表部分的实际高度,而不是显示的项目数。

示例:

<ComboBox Grid.Row="5" SelectedIndex="0" MaxDropDownHeight="100" x:Name="ComboBox1" ItemsSource="{Binding ComboxArr}"/>
<Button Grid.Row="6" Content="添加列表" Command="{Binding AddCom}" CommandParameter="123"></Button>
public List<string> ComboBoxList = new List<string>();
public ObservableCollection<string> ComboxArr { get; set; }public MainWindowViewModel()
{ComboBoxList.Add("item1");ComboBoxList.Add("item2");ComboBoxList.Add("item3");ComboBoxList.Add("item4");ComboBoxList.Add("item5");ComboxArr = new ObservableCollection<string>(ComboBoxList.ToArray());
}public void AddCom(string args)
{ComboBoxList.Add(args);ComboxArr = new ObservableCollection<string>(ComboBoxList.ToArray());this.RaisePropertyChanged(nameof(ComboxArr));
}

相关文章:

  • 二叉树|450.删除二叉搜索树中的节点
  • leetcode 1143.最长公共子序列
  • 【问题处理】蓝鲸监控-数据断点解决
  • ​LeetCode解法汇总518. 零钱兑换 II
  • MySQL内置函数
  • 解決flask-restful提示Did not attempt to load JSON data 问题
  • Python 文件操作-1
  • hdlbits系列verilog解答(Mux256to1)-63
  • PCL拟合并绘制平面(二)
  • 电阻的妙用:限流、分压、滤波,助力电路设计!
  • JavaScript Uncaught ReferenceError: WScript is not defined
  • JavaScript基础练习题之求斐波那契数列第N项的值
  • 【tips】Git使用指南
  • 【Java程序设计】【C00383】基于(JavaWeb)Springboot的水产养殖系统(有论文)
  • web渗透测试漏洞流程:红队目标信息收集之批量信息收集
  • ES6指北【2】—— 箭头函数
  • 《Java编程思想》读书笔记-对象导论
  • 【跃迁之路】【477天】刻意练习系列236(2018.05.28)
  • canvas 绘制双线技巧
  • django开发-定时任务的使用
  • dva中组件的懒加载
  • ESLint简单操作
  • Fabric架构演变之路
  • happypack两次报错的问题
  • HTTP中GET与POST的区别 99%的错误认识
  • JavaScript类型识别
  • Java基本数据类型之Number
  • java小心机(3)| 浅析finalize()
  • PHP 7 修改了什么呢 -- 2
  • PV统计优化设计
  • sessionStorage和localStorage
  • 大整数乘法-表格法
  • 构建二叉树进行数值数组的去重及优化
  • 关于Android中设置闹钟的相对比较完善的解决方案
  • 规范化安全开发 KOA 手脚架
  • 力扣(LeetCode)357
  • 聊一聊前端的监控
  • 扑朔迷离的属性和特性【彻底弄清】
  • 前端技术周刊 2019-01-14:客户端存储
  • 容器服务kubernetes弹性伸缩高级用法
  • 手写一个CommonJS打包工具(一)
  • 异步
  • media数据库操作,可以进行增删改查,实现回收站,隐私照片功能 SharedPreferences存储地址:
  • 摩拜创始人胡玮炜也彻底离开了,共享单车行业还有未来吗? ...
  • ​ 轻量应用服务器:亚马逊云科技打造全球领先的云计算解决方案
  • ​Distil-Whisper:比Whisper快6倍,体积小50%的语音识别模型
  • ​LeetCode解法汇总1410. HTML 实体解析器
  • ![CDATA[ ]] 是什么东东
  • # 执行时间 统计mysql_一文说尽 MySQL 优化原理
  • #NOIP 2014#day.2 T1 无限网络发射器选址
  • #vue3 实现前端下载excel文件模板功能
  • (06)金属布线——为半导体注入生命的连接
  • (2020)Java后端开发----(面试题和笔试题)
  • (C语言)输入一个序列,判断是否为奇偶交叉数
  • (Redis使用系列) SpringBoot 中对应2.0.x版本的Redis配置 一