[WPF] Using C # code to implement datatemplate

Source: Internet
Author: User

Http://www.cnblogs.com/chenlhuaf/archive/2009/02/11/1388426.html

 

 

Gridviewcolumn column = new gridviewcolumn ();
Gridviewcolumnheader H = new gridviewcolumnheader ();
H. content = "?????? ";
H. Tag = "*******";
Column. header = h;
Datatemplate dt = new datatemplate ();
Frameworkelementfactory FEF = new frameworkelementfactory (typeof (checkbox ));
Binding binding = new binding ();
Binding. Path = new propertypath ("marketindicator ");
FEF. setbinding (checkbox. contentproperty, binding );
FEF. setvalue (checkbox. foregroundproperty, brushes. White );
DT. visualtree = FEF;
Column. celltemplate = DT;
(This. lvexecutiontable. view as gridview). Columns. Add (column );

 

 

Http://hi.baidu.com/icexile/blog/item/2e75a73d47171108bba167e2.html

 

// a XAML is dynamically generated in the memory, describing a datatemplate
xnamespace NS = "http://schemas.microsoft.com/winfx/2006/xaml/presentation ";
xelement xdatatemplate =
New xelement (NS + "datatemplate", new xattribute ("xmlns", "http://schemas.microsoft.com/winfx/2006/xaml/presentation "),
New xelement (NS + "textblock",
New xelement (NS + "textblock", new xattribute ("width", "100 "), new xattribute ("text", "{binding Path = Name}"),
New xelement (NS + "textblock", new xattribute ("width ", "100"), new xattribute ("text", "{binding Path = Nick}")
);
// instantiate the in-memory XAML into a datatemplate object and assign it to the
// itemtemplate attribute of ListBox to complete data binding
xmlreader xr = xdatatemplate. createreader ();
datatemplate = xamlreader. load (xr) as datatemplate;
lstbox _. itemtemplate = datatemplate;
// bind the textbox to the name and Nick attributes of the current item respectively.
txtboxname _. setbinding (textbox. textproperty, "name");
txtboxnick _. setbinding (textbox. textproperty, "Nick");
}

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.