views:

19

answers:

1

hi, is it possiable to set 2 data field for an image control whiling binding

**<Image Source="{Binding ItemID, Converter={StaticResource IDToImageConverter}}" Height="50" />**  

now here i need to add one more value Price now. need to send even price as an paramter for IDToImageConverter function

how can i do it?

now i need to check first price value there are 3 condition i neeed to check

in my IDToImageConverter function

if( price> 5o)  
{
// then get the ItemID based on the value bind image here
if(ItemID >20)
{
// bind image1
}
if(ItemID >50)
{
// bind image2
}

}

if( price> 100)
{
// as above  codition we  do here
}

now how can i add these above functionality in IDToImageConverter ? any idea how i can solve it






<Image Source="{Binding ItemID, Converter={StaticResource IDToImageConverter}}" Height="50" />  
</DataTemplate>  
</data:DataGridTemplateColumn.CellTemplate>  
</data:DataGridTemplateColumn>  
</data:DataGrid.Columns>  
</data:DataGrid>  

public class IDToImageConverter : IValueConverter  
    {  
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
    {  
    Uri uri = new Uri("~/Images/" + value.ToString()+ ".jpg", UriKind.Relative);  
    return new BitmapImage(uri);  
    }

thanks in advance. for anyhelp you provide prince

A: 

Hi there,

out of the box, this is not possible. MultiBinding is not supported in SL and the ConverterParameter option is not bindable (otherwise, you could do something like Source={Binding ItemID, Converter={...}, ConverterParameter={Binding Price}} - but as I said, that's not possible).

IMHO, the best solution would be to provide an ImageUrl property in your ViewModel/data object that you can bind to:

public Uri ImageUrl
{
  get
  {
    if (Price > 50)
    {
      if (ItemID > 20)
        return new Uri("...");
      //...
    }
    //...
  }
}

If that's not an option, you could try the MultiBinding workaround described here: http://www.scottlogic.co.uk/blog/colin/2010/05/silverlight-multibinding-solution-for-silverlight-4/

Cheers, Alex

alexander.biskop
ok thanks for teh help
prince23