日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

Avalonia跨平台入门第十四篇之ListBox折叠列表

發(fā)布時(shí)間:2023/12/4 59 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Avalonia跨平台入门第十四篇之ListBox折叠列表 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在前面分享的幾篇中咱已經(jīng)玩耍了Popup、ListBox多選、Grid動(dòng)態(tài)分、RadioButton模板、控件的拖放效果、控件的置頂和置底、控件的鎖定、自定義Window樣式、動(dòng)畫(huà)效果、Expander控件;今天趁著空閑時(shí)間接著去摸索基于ListBox的折疊列表的效果,最終實(shí)現(xiàn)的效果如下圖:


先來(lái)看看布局吧:

前臺(tái)的布局代碼:

外面ListBox的子項(xiàng)模板:

<ListBox.ItemTemplate><DataTemplate><!--這里綁定ListBoxItem的IsSelected可以控制只展開(kāi)一項(xiàng)--><!--去掉綁定的話,可以展開(kāi)多項(xiàng)--><!--IsExpanded="{Binding $parent[ListBoxItem].IsSelected}"--><Expander Header="{Binding Name}" Cores:AttachedDependencyHelper.ExpanderHeaderImg="{Binding HeaderImg}" Foreground="White" Width="{Binding $parent[ListBox].Width}"HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"><ListBox Items="{Binding ChildData}" Width="260"ItemTemplate="{StaticResource LisBoxItemTemplate}"><ListBox.Styles><Style Selector="ListBoxItem /template/ Border#OutBorder"><Setter?Property="Background"?Value="#1C3466"/></Style><!--鼠標(biāo)pointerover的顏色--><Style Selector="ListBoxItem:pointerover /template/ Border#OutBorder"><Setter?Property="Background"?Value="#cc075c9f"/></Style><!--鼠標(biāo)selected的顏色--><Style Selector="ListBoxItem:selected /template/ Border#OutBorder"><Setter?Property="Background"?Value="#075C9F"/></Style></ListBox.Styles></ListBox></Expander></DataTemplate> </ListBox.ItemTemplate>

里面的ListBox的子項(xiàng)模板:

<DataTemplate x:Key="LisBoxItemTemplate"><Grid Width="{Binding $parent[ListBox].Width}"><WrapPanel Orientation="Horizontal" Margin="30,0,0,0" VerticalAlignment="Center"><Image Source="{Binding ManagerType,Converter={StaticResource ManagerTypeEnumToImageConverter}}" Height="20" Stretch="Uniform"/><TextBlock Margin="10,0,0,0" HorizontalAlignment="Center" Text="{Binding Path=Name,StringFormat={}我是{0}}" Foreground="White"/></WrapPanel><Button Classes="RemoveItemButton" Tag="{Binding}" IsVisible="{Binding $parent[ListBoxItem].IsSelected}" CommandParameter="{Binding .}"Command="{Binding DataContext.RemoveItemCommand,RelativeSource={RelativeSource AncestorType={x:Type ListBox} AncestorLevel=2}}"/></Grid> </DataTemplate>

最終簡(jiǎn)單的效果先這樣吧;回頭可以基于玩耍一下聯(lián)系人的效果;以后有時(shí)間的話,可以再去摸索一下更復(fù)雜的效果;編程不息、Bug不止、無(wú)Bug、無(wú)生活;改bug的冷靜、編碼的激情、完成后的喜悅、挖坑的激動(dòng) 、填坑的興奮;這也許就是屌絲程序員的樂(lè)趣吧;今天就到這里吧;希望自己有動(dòng)力一步一步堅(jiān)持下去;生命不息,代碼不止;大家抽空可以看看今天分享的效果,有好的意見(jiàn)和想法,可以在留言板隨意留言;我看到后會(huì)第一時(shí)間回復(fù)大家,多謝大家的一直默默的關(guān)注和支持!如果覺(jué)得不錯(cuò),那就伸出您的小手點(diǎn)個(gè)贊并關(guān)注一下,多謝您的支持!

總結(jié)

以上是生活随笔為你收集整理的Avalonia跨平台入门第十四篇之ListBox折叠列表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。