大周末的接著上一篇玩耍TreeView,這二天又再次去玩耍ListBox;畢竟是我的最愛,沒辦法就喜歡玩耍他;閑話也不多扯了,直接看咱們最終效果:
2、原來一直ItemTemplate,這次直接ListBoxItem的Template:
<Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ListBoxItem}"><Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"CornerRadius="4"Background="{TemplateBinding Background}"Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"><Grid><Grid.RowDefinitions><RowDefinition Height="*"/><RowDefinition Height="2.5*"/></Grid.RowDefinitions><Grid Margin="10,10,10,0"><TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=(ItemsControl.AlternationIndex),Converter={StaticResource AlternationIndexToNumberConverter}}"/><Rectangle Height="15" Width="15" HorizontalAlignment="Right" Fill="#89909C" Stroke="#E3E5E8"/></Grid><WrapPanel Orientation="Vertical" Grid.Row="1" Margin="10,10,10,0"><TextBlock Text="9/16"/><ProgressBar Width="80" Margin="0,6,0,0" Value="{Binding Percent}"Foreground="{Binding Status,Converter={StaticResource StatusToBrushConverter}}"/><TextBlock Text="{Binding Percent,StringFormat={}{0}%}" Margin="0,6,0,0"/></WrapPanel></Grid></Border></ControlTemplate></Setter.Value>
</Setter>
3、關于綁定索引需要前臺綁定一下
<ListBox?ItemsSource="{Binding?PortsList}"?AlternationCount="{Binding?PortsList.Count}"?Style="{StaticResource?PortsListListBox}"/>
4、關于ItemsPanel
<ItemsPanelTemplate x:Key="CommonItemsPanelTemplate"><WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
最終簡單的效果先這樣吧;以后有時間的話,可以再去摸索一下更復雜的效果
;編程不息、Bug不止、無Bug、無生活
;改bug的冷靜、編碼的激情、完成后的喜悅、挖坑的激動 、填坑的興奮;這也許就是屌絲程序員的樂趣吧;今天就到這里吧;希望自己有動力一步一步堅持下去;生命不息,代碼不止;大家抽空可以看看今天分享的效果,有好的意見和想法,可以在留言板隨意留言;我看到后會第一時間回復大家,多謝大家的一直默默的關注和支持!如果覺得不錯,那就伸出您的小手點個贊并關注一下,多謝您的支持!