c# - How to Bind to index in ItemsControl from DataTemplate in silverlight -



c# - How to Bind to index in ItemsControl from DataTemplate in silverlight -

i have silverlight application using itemscontrol. within of itemscontrol have datatemplate defined following:

xaml

<itemscontrol grid.row="1" grid.columnspan="5" x:name="dgodds"> <itemscontrol.itemtemplate> <datatemplate> <grid x:name="groot"> <grid.columndefinitions> <columndefinition width="200"/> <columndefinition width="200"/> <columndefinition width="200"/> </grid.columndefinitions> <textbox x:name="of1" grid.column="0" text="{binding oddfactor, mode=twoway}" fontweight="bold" verticalalignment="center" horizontalcontentalignment="center"/> <textbox x:name="ofx" grid.column="1" text="{binding oddfactor, mode=twoway}" fontweight="bold" verticalalignment="center" horizontalcontentalignment="center"/> <textbox x:name="of2" grid.column="2" text="{binding oddfactor, mode=twoway}" fontweight="bold" verticalalignment="center" horizontalcontentalignment="center"/> </grid> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol>

i have list of objects:

c#

observablecollection<testobj> somelist = new observablecollection<testobj>; somelist.add(new testobj(){ oddtype = 1, oddfakctor = 1.1 }); somelist.add(new testobj(){ oddtype = 2, oddfakctor = 2.2 }); somelist.add(new testobj(){ oddtype = 3, oddfakctor = 3.3 }); this.dgodds.itemssource = this.collection;

the testobj class follows:

public class testobj { public double oddtype { get; set;} public double oddfakctor { get; set; } }

i want display properties in controls like:

if oddtype equal 1, show in textbox x:name="of1", if oddtype equal 2, show in textbox x:name="ofx", if oddtype equal 3, show in textbox x:name="of3"

how this?

since u want show oddtype equals 1 or 2 or 3, u can have single textblock. if 1 selected, 1 of textbox have of1 , others null.

private double _oddfactor; public double oddfakctor { { homecoming _oddfactor; } set { _oddfactor = value; onpropertychanged(() => oddfakctor); } }

if here u update _oddfakctor , bind text box value wat u r passing _oddfactor

c# silverlight

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -