I have a grid, that needs to have an image displayed in a column. This image will be different for each row depending on several other columns in the row.
Here is my xaml for the unbound column
<igGrid:UnboundColumn Key="Status" HeaderText=" " Width="30"> <igGrid:UnboundColumn.ItemTemplate> <DataTemplate > <Image Stretch="Fill" Width="20" Source="" /> </DataTemplate> </igGrid:UnboundColumn.ItemTemplate></igGrid:UnboundColumn>
I'm not sure I got the xaml correct but if I hardcode Source property, everything displays properly.
Is there anyway in the InitializeRow function of the grid that I could set the source property on the image for that row?
Any help would be greatly appreciated.
I figured out how to get this working so I figured I'd post for anyone else who ever is trying to do this.
I changed my xaml for the image to
<igGrid:ImageColumn Key="Status" HeaderText=" " />
I then added a public property to the object I was binding to. In our case, its a POCO object that mimics a DataRow object. So in my datarow object, i put this property in it.
public System.Windows.Media.Imaging.BitmapImage Status{ get { Uri uri = null; if (this.StatIncomplete || this.StatRejected) uri = new Uri(@"/Modules.Common;component/Images/fail.png", UriKind.Relative); else if (this.StatOutdated) uri = new Uri(@"/Modules.Common;component/Images/warning.png", UriKind.Relative); else if (this.StatTestData) uri = new Uri(@"/Modules.Common;component/Images/new_16.png", UriKind.Relative); System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage(uri); return (image); } }
I'd still like to know how to access it from the InitializeRow if anyone has any ideas.
Why would you need to set the Source property on the image?
Since you have a property set up, assuming your object implements INotifyPropertyChanged and that interface is used, you should be be able to get the Status to switch automatically.
In this case, again assuming you implemented INotifyPropertyChanged, when StatIncomplete, StatRejected, StatOutdated toggle in value you should notify that the "Status" field property also changed.
Something like this:
<ig:XamWebGrid x:Name="grid">
<ig:XamWebGrid.EditingSettings>
<ig:EditingSettings AllowEditing="Cell" ></ig:EditingSettings>
</ig:XamWebGrid.EditingSettings>
<ig:XamWebGrid.Columns>
<ig:ImageColumn Key="Status"></ig:ImageColumn>
</ig:XamWebGrid.Columns>
</ig:XamWebGrid>
public partial class MainPage : UserControl
{
public MainPage()
InitializeComponent();
List<MyObject> o = new List<MyObject>();
o.Add(new MyObject() { ShowRed=false, ShowBlue=true });
o.Add(new MyObject() { ShowRed = true, ShowBlue = false });
o.Add(new MyObject() { ShowRed = true, ShowBlue = true });
o.Add(new MyObject() { ShowRed = false, ShowBlue = false });
grid.ItemsSource = o;
}
public class MyObject :INotifyPropertyChanged
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
#endregion
public Uri Status
get
if (this.ShowBlue)
return new Uri("Blue.png",UriKind.Relative );
if (this.ShowRed)
return new Uri("Red.png", UriKind.Relative);
return new Uri("Yellow.png", UriKind.Relative);
bool _showRed;
public bool ShowRed
return this._showRed;
set
if (this._showRed != value)
this._showRed = value;
this.OnPropertyChanged("ShowRed");
this.OnPropertyChanged("Status");
bool _showBlue;
public bool ShowBlue
return this._showBlue;
if (this._showBlue != value)
this._showBlue = value;
this.OnPropertyChanged("ShowBlue");