c# - WPF add image to cell in column -


using c#.net4.5, visual studio 2012, wpf.

well here's how far got lot of great people , advice!

set new column images:

datagridtemplatecolumn p1 = new datagridtemplatecolumn(); p1.header = "p1"; frameworkelementfactory factory1 = new frameworkelementfactory(typeof(system.windows.controls.image)); binding b1 = new binding("picture"); b1.mode = bindingmode.twoway; factory1.setvalue(system.windows.controls.image.sourceproperty, b1); datatemplate celltemplate1 = new datatemplate(); celltemplate1.visualtree = factory1; p1.celltemplate = celltemplate1; paretogrid.columns.add(p1); 

then check each "row" , set ifs check values:

private void showarrows() {     var rows = getdatagridrow(paretogrid);       foreach (datagridrow r in rows)     {         datarowview rv = (datarowview)r.item;         var par3 = paretogrid.columns[7].getcellcontent(paretogrid.items[2]) textblock;         int pconv3 = convert.toint32(par3.text);         var par2 =  paretogrid.columns[8].getcellcontent(paretogrid.items[2]) textblock;         int pconv2 = convert.toint32(par2.text);         var par1 = paretogrid.columns[9].getcellcontent(paretogrid.items[2]) textblock;         int pconv1 = convert.toint32(par1.text);         var parnew = paretogrid.columns[10].getcellcontent(paretogrid.items[2]) textblock;         int pconvnew = convert.toint32(parnew.text);          if(pconv3 == pconv2)         {             paretogrid.columns[12].         }else              if(pconv3 > pconv2)             {                 //uparrow             }             else                  if (pconv3 < pconv2)                 {                     //down                 }     } } 

so can see step through, throw few nested conditions comments want add images, :

paretogrid.columns[12].setvalue(can image go here? asks dependency); 

not sure how add image see adding images entire column via item source.

where going wrong?

edit: 08/04/2013 ok got 2 suggestions, far no errors happening nice me. unfortunatly no images showing up.

datagrid.children.add(); 

for reason datagrid not have .children method in intellisense, when force it redlines me. missing?

not big on xaml heres grid.

grid margin="10,13,6,-13" background="{dynamicresource {x:static systemcolors.activecaptiontextbrushkey}}" horizontalalignment="left" width="1442">                 <datagrid name ="paretogrid"  horizontalalignment="left" height="500" margin="16,63,0,0" verticalalignment="top" width="1126" rendertransformorigin="0.5,0.5" background="{x:null}" fontsize="14" selectionchanged="paretogrid_selectionchanged"> 

i don't have environment (vs2012 , windows 8), in wpf can access properties setvalue() method. try use this:

 image img = new image();  img.setvalue(grid.columnproperty, "2");  img.setvalue(grid.rowproperty, "1"); 

hope helps.

i have tested small demo on machine , works well. here xaml:

<window x:class="wpfapplication1.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="mainwindow" height="350" width="525"> <grid x:name="paretogrid">     <grid.rowdefinitions>         <rowdefinition/>         <rowdefinition/>     </grid.rowdefinitions>     <grid.columndefinitions>         <columndefinition/>         <columndefinition/>     </grid.columndefinitions> </grid> 

and code behind:

 var img = new image {width = 100, height = 100};  var bitmapimage= new bitmapimage (new uri(@"pack://application:,,,/images/old-go-down.png"));   img.source = bitmapimage;   img.setvalue(grid.rowproperty, 1);  img.setvalue(grid.columnproperty, 1);   paretogrid.children.add(img); 

image build action has set resource.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -