c# - WPF DataGrid: how to show object with double values -
i have object this:
public class mchistructure { [system.runtime.serialization.optionalfield(versionadded = 2)] public double chiv1plus; [system.runtime.serialization.optionalfield(versionadded = 2)] public double chiv1minus; [system.runtime.serialization.optionalfield(versionadded = 2)] public double mv1plus; ... }
and have datagrid shows, in first column, variable names and, in second column, double values. know if there possibility hide of values (for example, if 1 negative must hidden)
thanks all
it code behind application, @ first yo should create model class , populate code-behind. that's all. please, see example:
model:
public class mchistructure { public string titlefield { get; set; } public double chiv1plus { get; set; } public double chiv1minus { get; set; } public double mv1plus { get; set; } }
code-behind of window:
public mainwindow() { initializecomponent(); filldatagrid(); } private void filldatagrid() { observablecollection<mchistructure> coll = new observablecollection<mchistructure>(); (int start = 0; start < 10; start++) { coll.add(new mchistructure(){titlefield="title " + start.tostring(), chiv1minus=start-1, chiv1plus=start+1, mv1plus=start-1}); } datagrid.itemssource = coll; }
and xaml:
<datagrid name="datagrid"/>
update. using listview:
xaml:
<listview name="listview"> <listview.itemtemplate> <datatemplate> <border borderbrush="brown" borderthickness="1" cornerradius="5"> <stackpanel> <stackpanel orientation="horizontal"> <textblock text="chiv1plus:" margin="2" fontweight="bold"/> <textblock text="{binding chiv1plus}" margin="2" /> </stackpanel> <stackpanel orientation="horizontal"> <textblock text="chiv1minus:" margin="2" fontweight="bold"/> <textblock text="{binding chiv1minus}" margin="2" /> </stackpanel> <stackpanel orientation="horizontal"> <textblock text="mv1plus:" margin="2" fontweight="bold" /> <textblock text="{binding mv1plus}" margin="2" /> </stackpanel> </stackpanel> </border> </datatemplate> </listview.itemtemplate> </listview>
c# in code-behind:
public mainwindow() { initializecomponent(); filllistview(); } private void filllistview() { list<mchistructure> coll = new list<mchistructure>(); (int start = 0; start < 10; start++) { coll.add(new mchistructure() { titlefield = "your title: " + start.tostring(), chiv1minus = start - 1, chiv1plus = start + 1, mv1plus = start - 1 }); } listview.itemssource = coll; }
model:
public class mchistructure { public string titlefield { get; set; } public double chiv1plus { get; set; } public double chiv1minus { get; set; } public double mv1plus { get; set; } }
it looks this:
Comments
Post a Comment