WPF中的ListBox實現(xiàn)按塊顯示元素的方法
本文實例講述了WPF中的ListBox實現(xiàn)按塊顯示元素的方法。分享給大家供大家參考,具體如下:
注意:需要設置ListBox的屬性 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
關鍵代碼,WPF中有內(nèi)置的WrapPanel控件,在ListBox.ItemsPanel中使用可以讓元素按塊顯示
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox Height="304" HorizontalAlignment="Left" Margin="14,143,0,0" Name="lstTables" VerticalAlignment="Top" Width="615" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="20,20,20,20">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Image Source="Images/table.png" Grid.Row="0" Height="42" Width="42" HorizontalAlignment="Center">
<Image.Effect>
<DropShadowEffect/>
</Image.Effect>
</Image>
<TextBlock Text="{Binding FTableName,Mode=TwoWay}" Grid.Row="1" HorizontalAlignment="Center" Margin="5,5,5,5" />
<CheckBox IsChecked="{Binding FSelected,Mode=TwoWay,Converter={StaticResource SelCTS}}" Grid.Row="2" HorizontalAlignment="Center">
<CheckBox.Effect>
<DropShadowEffect/>
</CheckBox.Effect>
</CheckBox>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
更多關于C#相關內(nèi)容感興趣的讀者可查看本站專題:《C#窗體操作技巧匯總》、《C#常見控件用法教程》、《WinForm控件用法總結(jié)》、《C#程序設計之線程使用技巧總結(jié)》、《C#操作Excel技巧總結(jié)》、《C#中XML文件操作技巧匯總》、《C#數(shù)據(jù)結(jié)構與算法教程》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O計入門教程》
希望本文所述對大家C#程序設計有所幫助。
相關文章
C#實現(xiàn)讀取匿名對象屬性值的方法示例總結(jié)
這篇文章主要介紹了C#實現(xiàn)讀取匿名對象屬性值的方法,結(jié)合實例形式總結(jié)分析了C#通過反射、轉(zhuǎn)換等方法讀取匿名對象屬性值的相關操作技巧,需要的朋友可以參考下2020-03-03
C#編程實現(xiàn)統(tǒng)計文件夾內(nèi)文件和隱藏文件的方法示例
這篇文章主要介紹了C#編程實現(xiàn)統(tǒng)計文件夾內(nèi)文件和隱藏文件的方法,結(jié)合具體實例形式分析了C#針對文件與目錄的遍歷及屬性操作相關技巧,需要的朋友可以參考下2017-07-07

