Listview and gridview

Source: Internet
Author: User

This afternoon, listview was used when we were working on the Olympic security system. Therefore, we recorded someCode...
There is no content to introduce. You can understand the code at a glance ..

XAML File Settings
<Listview name = "bscandmsclistview" maxheight = "200" maxwidth = "250" verticalignment = "TOP" opacity = "0.8" itemssource = "{binding}">
<Listview. View>
<Gridview allowscolumnreorder = "true">

</Gridview>
</Listview. View>
</Listview>

Background code:

Gridview tempgridview = (gridview) This. bscandmsclistview. view;

Foreach (datacolumn Col in resulttable. columns)
{
Gridviewcolumn GVC = new gridviewcolumn ();
GVC. header = col. columnname;
Binding binding = new binding ();
Binding. Path = new propertypath (Col. columnname );
GVC. displaymemberbinding = binding;
Tempgridview. Columns. Add (GVC );
}

This. bscandmsclistview. datacontext = resulttable;

This is the bound table.
There is also an object bound to implement ienumrable <t>... (no such code ..)

It seems that you can also set the template of the gridview column and add some controls...
(The following code is excerpted from the Internet)

 
Gridviewcolumn gvcname = new gridviewcolumn (); gvcname. header = "name"; datatemplate nametemplate = new datatemplate (); frameworkelementfactory namefactory = new frameworkelementfactory (typeof (contactpropertylabel); binding = new binding ("name"); binding. mode = bindingmode. twoway; namefactory. setbinding (contentproperty, binding); nametemplate. visualtree = namefactory; gvcname. celltemplate = nametemplate; gvcontactlist. columns. add (gvcname );

This code can bind a column of A listview in two directions and specify the Rendering Control for this row.

Binding stronger than Windows Forms

Public class contact: dependencyobject {public static dependencyproperty nameproperty = dependencyproperty. register ("name", typeof (string), typeof (contact); Public string name {get {return (string) getvalue (nameproperty);} set {setvalue (nameproperty, value );}}}

Dependencyobject + dependencyproperty enables attribute settings to automatically trigger the valuechanged event and update binding.

At the same time, scrollviewer and animation are also used ..

Front-end:

<Scrollviewer name = "listscroll" horizontalalignment = "Left" verticalignment = "TOP" margin = "0, 30, 0" width = "10"
Verticalscrollbarvisibility = "Auto" maxheight = "700">
<! -- Data list -->
<Listview name = "tkgplistview" maxheight = "700" verticalalignment = "TOP">
<Listview. View>
<Gridview allowscolumnreorder = "true">

</Gridview>

</Listview. View>
</Listview>
</Scrollviewer>

Background:
Listscroll. mouseenter + = new mouseeventhandler (listscroll_mouseenter );
Listscroll. mouseleave + = new mouseeventhandler (listscroll_mouseleave );

Private void listscroll_mouseenter (Object sender, mouseeventargs E)
{
Gridview tkgpgridview = tkgplistview. view as gridview;
If (tkgpgridview = NULL | tkgpgridview. Columns. Count <1)
Return;
Int iwidth = 0;
Foreach (gridviewcolumn Col in tkgpgridview. columns)
{
Iwidth + = (INT) COL. actualwidth;
}
Doubleanimation mydoubleanimationwidth = new doubleanimation ();
Mydoubleanimationwidth. To = iwidth + 40;
Mydoubleanimationwidth. Duration = new duration (timespan. fromseconds (APP) application. Current). animationduration ));
Mydoubleanimationwidth. autoreverse = false;
Listscroll. beginanimation (scrollviewer. widthproperty, mydoubleanimationwidth );
}

Private void listscroll_mouseleave (Object sender, mouseeventargs E)
{
Doubleanimation mydoubleanimationwidth = new doubleanimation ();
Mydoubleanimationwidth. To = 10;
Mydoubleanimationwidth. Duration = new duration (timespan. fromseconds (APP) application. Current). animationduration ));
Mydoubleanimationwidth. autoreverse = false;
Listscroll. beginanimation (scrollviewer. widthproperty, mydoubleanimationwidth );
}

Add by Yan Chang steel 20080603 ....

an animation is usually placed in a storyboard control. There are also a lot of animations, as shown in the figure above, corresponding to doubleanimation, and the animation generated when the corresponding property type is double. Of course, this property must be dependences .. at the same time, there are some other animations, including coloranimation and so on... record it in this place first, and then start writing slowly...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.