Mobile wallpaper 1Mobile wallpaper 2Mobile wallpaper 3Mobile wallpaper 4Mobile wallpaper 5Mobile wallpaper 6Mobile wallpaper 7Mobile wallpaper 8
90 字
1 分钟
在Avalonia自定义ItemControl内容

自定义ItemControl#

<ItemsControl ItemsSource="{TemplateBinding ItemsSource}">
<ItemsControl.ItemsPanel>
// 自定义ItemControl布局
<ItemsPanelTemplate>
<UniformGrid
HorizontalAlignment="Center"
VerticalAlignment="Top"
ColumnSpacing="8"
Columns="3"
RowSpacing="5"
Rows="4"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
// 自定义ItemControl的每一个Item
<DataTemplate x:DataType="models:VoiceItem"> // 指定数据模型
<controls:VoiceItem
// 绑定model:VoiceItem里的 Title, BackgroundImage, CharacterName
Title="{Binding Title}"
BackgroundImage="{Binding BackgroundImage}"
CharacterName="{Binding CharacterName}"
// 绑定父类的Command命令
Command="{Binding $parent[controls:VoiceItemPanel].Command}"
// 绑定数据为自己
CommandParameter="{Binding}"
DeleteCommand="{Binding $parent[controls:VoiceItemPanel].DeleteCommand}"
MoveCommand="{Binding $parent[controls:VoiceItemPanel].MoveCommand}"
Text="{Binding Text}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
在Avalonia自定义ItemControl内容
https://mikuas.top/posts/avalonia/custom_item_control/
作者
Mikuas
发布于
2026-03-08
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时