The example in this article describes the custom layout usage of the ListView control for WPF. Share to everyone for your reference, specific as follows:
Profile:
In the form of the source code posted, lest forget, and then to the online search data. Debugging through the VS2008+SP1 environment
The referenced Grayscaleeffect module can be downloaded from the location in the reference "grayscale Effect ...".
Body:
How the layout is defined in the App.xaml source code as follows
<application x:class= "Cwebssynassistant.app" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:effect=" clr-namespace:grayscaleeffect;assembly= Grayscaleeffect "startupuri=" Window1.xaml "> <Application.Resources> <!--listview layout Templates--> Ontroltemplate x:key= "Mylvtemplate" targettype= "{x:type ListView}" > <Grid> <scrollviewer x:name= "Scrollviewerelement" background= "white" verticalscrollbarvisibility= "Auto" Horizontal scrollbarvisibility= "Disabled" > <ItemsPresenter> </ItemsPresenter> </scrollv Iewer> </Grid> </ControlTemplate> <!--listviewitem Layout template--> <datatemplate x:key=
"Mylvitemtemplate" > <grid name= "mygrid" width= "" margin= "8,8,0,0" > <Grid.RowDefinitions> <rowdefinition height= "Auto"></RowDefinition> <rowdefinition height= "Auto" ></RowDefinition> </grid.rowdefini tions> <image name= "img" source= "{Binding path=isource}" horizontalalignment= "Center" width= "32"
height= "stretch=" "UniformToFill" tooltip= "{Binding path=fullfilename}" > <Image.Effect> <effect:grayscaleeffect x:name= "Grayscaleeffect" desaturationfactor= "1.0"/> </image.effect > </Image> <textblock name= "Imgtitle" text= "{Binding path=filename}" grid.row= "1" Horizontalal Ignment= "Center" fontsize= "a" fontfamily= "Arial" tooltip= "{Binding path=fullfilename}" Margin = "4,4,4,4" texttrimming= "characterellipsis"/> </Grid> <DataTemplate.Triggers> <data Trigger binding= "{Binding relativesource={relativesource mode=findancestor, Ancestortype={x:type ListViewItem}}, path=isselected} "Value= "True" > <setter targetname= "mygrid" property= "Background" value= "white"/> <setter targetn Ame= "Imgtitle" property= "Background" value= "Cadetblue"/> <setter targetname= "Imgtitle" property= "Foregroun"
D "value=" white "/> <setter targetname=" img "property=" Effect "> <Setter.Value> <effect:grayscaleeffect desaturationfactor= "0.5"/> </Setter.Value> </setter>
; <!--<setter targetname= "img" property= "Opacity" value= ". 5" ></Setter>--> &L T;/datatrigger> </DataTemplate.Triggers> </DataTemplate> <!--The following code is not used, when selected, some edges of the border will become blue (not your hope Look at the color)--> <style targettype= "{x:type ListViewItem}" x:key= "Itemcontainerstyle" > <setter Property= "Tem Plate "> <Setter.Value> <controltemplate targettype=" {x:type ListViewItem} "> & Lt Border x:Name= "Bd" background= "{templatebinding Background}" borderbrush= "{TemplateBinding BorderBrush}" borderthic kness= "0" > <ContentPresenter/> </Border> <controltemplate.trigger s> <trigger property= "isselected" value= "true" > <setter property= "Background" Ta Rgetname= "Bd" value= "white"/> </Trigger> </ControlTemplate.Triggers> &L t;/controltemplate> </Setter.Value> </Setter> </Style> </application.resources
> </Application>
How to refer to the Windows1.xaml in the definition of source code as follows
<listview x:name= "ListView1" itemtemplate= "{StaticResource mylvitemtemplate}"
template= "{StaticResource Mylvtemplate} "itemcontainerstyle=" {StaticResource Itemcontainerstyle} " margin=" mousedoubleclick= "Onlocalfsopen" grid.row= "2" >
<!--define Warppanel below, so that item items are arranged from left to right in the container-->
< itemscontrol.itemspanel>
<ItemsPanelTemplate>
<WrapPanel/>
</itemspaneltemplate >
</ItemsControl.ItemsPanel>
</ListView>
Resources:
>>WPF ListBox Tutorial
http://www.c-sharpcorner.com/uploadfile/mahesh/listbox-in-wpf/
>>drag and Drop, cut/copy and paste files with Windows Explorer
Http://www.codeproject.com/Articles/14059/Drag-and-drop-cut-copy-and-paste-files-with-Window
>>data Templating Overview
Http://msdn.microsoft.com/en-us/library/ms742521.aspx
>>WPF ListBox Selection Color
Http://stackoverflow.com/questions/794792/wpf-listbox-selection-color
>>WPF tutorial-using The ListView, part 3-in Place Edit
Http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-3-in-place-edit
>>creating a Custom Markup Extension in WPF (and soon, Silverlight)
Http://10rem.net/blog/2011/03/09/creating-a-custom-markup-extension-in-wpf-and-soon-silverlight
>>more WPF Custom effects:motion Blur and grayscale Samples
Http://windowsclient.net/wpf/wpf35/wpf-35sp1-more-effects.aspx
>>WPF Tutorial-controls and Layout
Http://www.mini.pw.edu.pl/~mossakow/materials/presentations/wpf.3.5/controls_layout/index.html
>>grayscale effect-a Pixel Shader Effect in WPF
Http://bursjootech.blogspot.com/2008/06/grayscale-effect-pixel-shader-effect-in.html
>>SHADERPAD-WPF shadereffects
http://shaderpad.codeplex.com/
Read more about C # Interested readers can view the site topics: "C # form Operation Tips Summary", "C # Common control usage Tutorial", "WinForm Control Usage Summary", "C # Programming Thread Usage Skills summary", "C # Operation Excel Skills Summary", "C # Summary of operational skills in XML files, C # tutorial on data structure and algorithms, C # array operation techniques Summary, and C # Introduction to object-oriented Programming
I hope this article will help you with C # programming.