日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

ItemsControl 解析

發布時間:2023/11/27 生活经验 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ItemsControl 解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?先上個示例

  <ItemsControl Margin="10"   ItemsSource="{Binding}" Name="itemsControl">
<ItemsControl.Template><ControlTemplate  TargetType="{x:Type ItemsControl}"><Border CornerRadius="5"><ScrollViewer VerticalScrollBarVisibility="Auto" ><ItemsPresenter   /></ScrollViewer></Border></ControlTemplate></ItemsControl.Template><ItemsControl.ItemsPanel><ItemsPanelTemplate><WrapPanel  Name="wp" /></ItemsPanelTemplate></ItemsControl.ItemsPanel><ItemsControl.ItemTemplate><DataTemplate><Image Source="{Binding XPath=@}" /></DataTemplate></ItemsControl.ItemTemplate></ItemsControl>

ItemsControl 是一種數據展示控件,大致分為三個部分組成:Template, ItemTemplate, ?ItemsPanel.

?

  1. 先說 Template ,Template 是整個控件的架構設計,最外面放什么的東東,里面放什么東東,都在這里控制,負責宏觀的結構,下面這個例子:最外面是一個border,然后要放一個ScrollViewer用來滾動展示,滾動的內容,就由ItemsPresenter 來決定。對應blend菜單:右鍵—>Edit Template

? ???<ItemsControl.Template>

??????????? <ControlTemplate ?TargetType="{x:Type ItemsControl}">

??????????????? <Border CornerRadius="5">

??????????????????? <ScrollViewer VerticalScrollBarVisibility="Auto" >

??????????????????????? <ItemsPresenter? ?/>

??????????????????? </ScrollViewer>

??????????????? </Border>

??????????? </ControlTemplate>

??????? </ItemsControl.Template>

2. 再說ItemsPanel,作為數據展示,總要有個容器吧,這個panel就是為了設置容器用的,設置為StackPanel,WrapPanel都可以,足夠靈活,對應上一條中的ItemsPresenter,

對應blend菜單 :右鍵--àEdit Additional TemplatesàEdit? Layout? Items(ItemsPanel)?

?例如:

??????? <ItemsControl.ItemsPanel>

??????????? <ItemsPanelTemplate>

??????????????? <WrapPanel ?Name="wp" ?/>

??????????? </ItemsPanelTemplate>

??????? </ItemsControl.ItemsPanel>

?3.?最后是ItemTemplate , 每一個數據條目應該是個什么樣子,負責具體呈現的,例如數據項是一個圖片,那就用圖片來顯示,

對應blend菜單 :右鍵--à Edit Additional TemplatesàEdit ?Generated ?Items(ItemsTemplate)?

? <ItemsControl.ItemTemplate>

????? <DataTemplate>

???????? <Image Source="{Binding XPath=@}" />

???? </DataTemplate>

</ItemsControl.ItemTemplate>
4. 附帶一個,ItemContainerStyle ,也就是控制每個數據條目的顯示樣式,例如,想要在上例中的Image外面加一個邊框,

對應blend菜單 :右鍵--à Edit Additional TemplatesàEdit? Generated? Item Container (ItemContainerStyle)?

?? <ItemsControl.ItemContainerStyle>

??????????? <Style TargetType="{x:Type ListBoxItem}">

??????????????? <Setter Property="Template">

??????????????????? <Setter.Value>

??????????????????????? <ControlTemplate TargetType="{x:Type ListBoxItem}">

??????????????????????????? <Border BorderBrush="Black" BorderThickness=".5" Height="100">

??????????????????????????????? <ContentPresenter />

??????????????????????????? </Border>

??????????????????????? </ControlTemplate>

??????????????????? </Setter.Value>

??????????????? </Setter>

??????????? </Style>

??????? </ItemsControl.ItemContainerStyle>

?

搞了很久才明白這么多東東,感覺微軟把這事搞復雜了,要是像asp.net 里面repeater或者datalist那種弄法,會簡單很多哦。

轉載于:https://www.cnblogs.com/xiaokang088/archive/2011/04/15/2016719.html

總結

以上是生活随笔為你收集整理的ItemsControl 解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。