locked
Valueconverter value parameter is always NULL RRS feed

  • Question

  • Hello,

    I  am using VS2010 b2 with SL4 in a RIA services business project, and have a datagrid bound to a SQL DB through the ADO.NET Entity framework. I'm trying to use a valueconverter to take a string value and use it to lookup an image blob in the DB. The value parameter to Convert is always null.

    So the Picture column in the database has the file name to use for the image that is stored as an image blob in the same database in another table. I have mapped the Picture column as an Image in the VS2010 data sources window so it will display the image in the datagrid, however the underlying (Picture column) is an nvarchar(100) that is always sent to the Convert method as NULL. Am I missing something here?

    Here's some code snippets:

     <data:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding ElementName=axPersonDomainDataSource, Path=Data}" Name="axPersonDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalContentAlignment="Stretch" Grid.ColumnSpan="2" ColumnWidth="Auto" Margin="0,0,0,1" Grid.RowSpan="7" DataContext="{Binding}">

    <
    data:DataGrid.Columns>
    <data:DataGridTemplateColumn x:Name="pictureColumn" Header="Picture" Width="SizeToHeader">
    <data:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
    <Image Source="{Binding Path=Picture, Converter={StaticResource CardholderImageConverter1}, ConverterParameter=pictureColumn}" DataContext="{Binding}" />
    </DataTemplate>
    </data:DataGridTemplateColumn.CellTemplate>
    </data:DataGridTemplateColumn>

    And:

     public class CardholderImageConverter : IValueConverter

    {

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
             if (value == null) 
                return null;
    .

    My understanding is that the value parameter should be from the source of my binding. The column in question is populated in the database as a nvarchar(100) and I need this string to use inside the Convert method to perform an Entity query. But it is always null. What would be any causes for this value to be null?

    Inside Convert method:
    Cardholder ch = new Cardholder();
    EntityQuery<Files> query = from c in ch.GetFilesQuery()
    where c.Name == value as string
    select c;

    // create BitmapImage set source to the results of the above query -- this works BTW

    Thanks in advance for any help you may have.

    Victor

    Thursday, January 21, 2010 10:33 PM

Answers

  • It now works.  The only thing I did was to bring up the Data source picker in the properties window in VS, for the datagrid's image control, and saw that it had an error with stringToUnescape which I believe is related to the Uri for the image source. So I set a default value for it, and presto it started working.

    Apparently you need to set some default value when there are NULLS in the database rows that have no images. Turns out this was the first couple of rows in the database, so it would error out and not recover.   

    The data source picker, accessible via Document Outline, is new in VS2010 so perhaps has a bug.

    Victor

    • Marked as answer by Victor Grippi Tuesday, January 26, 2010 6:46 PM
    Tuesday, January 26, 2010 6:46 PM

All replies

  • It now works.  The only thing I did was to bring up the Data source picker in the properties window in VS, for the datagrid's image control, and saw that it had an error with stringToUnescape which I believe is related to the Uri for the image source. So I set a default value for it, and presto it started working.

    Apparently you need to set some default value when there are NULLS in the database rows that have no images. Turns out this was the first couple of rows in the database, so it would error out and not recover.   

    The data source picker, accessible via Document Outline, is new in VS2010 so perhaps has a bug.

    Victor

    • Marked as answer by Victor Grippi Tuesday, January 26, 2010 6:46 PM
    Tuesday, January 26, 2010 6:46 PM
  • Hi Victor,

    I found something similar when working with the RIA framework for SL. When committing new objects even if the colum allowed for NULLs the objects wouldn't get created in the database. No specific exception is thrown. To be on the safe side I would always explicitly set any field value to a NON NULL variant.

    Sean.
    Wednesday, January 27, 2010 11:09 AM