Problem showing images with GridViewImageColumn

4 posts, 0 answers
  1. Fernando Real
    Fernando Real avatar
    6 posts
    Member since:
    Mar 2010

    Posted 24 Jan 2012 Link to this post

    Hello all,

    I've been experiencing some trouble displaying images in GridViewImageColumn. I think I have everything ok, but no image is displayed. The other columns are filled ok.

    Here is my XAML code:

    <telerik:RadGridView x:Name="AlarmGridView" EnableRowVirtualization="True" DataLoadMode="Asynchronous" ItemsSource="{Binding Events}"
                                 RowStyleSelector="{StaticResource backgroundColorStyle}" ActionOnLostFocus="None"
                                 IsReadOnly="True" AutoGenerateColumns="False" Grid.Row="1" HeaderRowStyle="{StaticResource GridViewHeaderRowStyle1}">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewImageColumn DataMemberBinding="{Binding evento, Converter={StaticResource ConvertEventToImage}}" >
                        <telerik:GridViewImageColumn.ToolTipTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding evento}" />
                            </DataTemplate>
                        </telerik:GridViewImageColumn.ToolTipTemplate>
                    </telerik:GridViewImageColumn>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding data}" Header="Data Hora" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding descricao}" Header="Descrição" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding evento}" Header="Evento" IsVisible="False" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding estado}" Header="Estado" IsVisible="False"/>
                </telerik:RadGridView.Columns>
                <telerik:RadContextMenu.ContextMenu>
                    <telerik:RadContextMenu  x:Name="GridContextMenu"  Opened="GridContextMenu_Opened" >
                        <telerik:RadMenuItem Header="Marcar como Visto" Name="VistoMenuItem" Visibility="Collapsed"/>
                        <telerik:RadMenuItem Header="Marcar como Novo" Name="NovoMenuItem" Visibility="Collapsed"/>
                        <telerik:RadMenuItem Header="Iniciar Serviço" Name="ISMenuItem" Visibility="Collapsed"/>
                        <telerik:RadMenuItem Header="Iniciar Viagem" Name="IVMenuItem" Visibility="Collapsed"/>
                        <telerik:RadMenuItem Header="Observações" Name="ObsMenuItem" Visibility="Collapsed"/>
                        <telerik:RadMenuItem Header="Aceitar Duplo-Click" Name="DCMenuItem" Visibility="Collapsed"/>
                        <telerik:RadMenuItem Header="Fim de Viagem" Name="FVMenuItem" Visibility="Collapsed"/>
                    </telerik:RadContextMenu>             
                </telerik:RadContextMenu.ContextMenu>
            </telerik:RadGridView>

    Here is my converter (just a stub):

    public class ConverterFromEventToImage : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                BitmapImage image;
                string Event = (string)value;
                image = new BitmapImage(new Uri("male.jpg", UriKind.Relative));
                return image;
            }

            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return null;
            }
        }


    Is anything missing?

    Thanks in advance.

    Best regards,

    Fernando
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Jan 2012 Link to this post

    Hi Fernando,

    Everything seems correct from the snippet you provided. The only thing that might be causing the issue is if the image url is not defined correctly - is the image placed in a folder for example ? I have tested the case with:

    BitmapImage image;         
    image = new BitmapImage(new Uri("../img/myImage.jpg", UriKind.Relative));
    return image;

    where img is a folder where the image is placed. In that way everything works correctly.

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Fernando Real
    Fernando Real avatar
    6 posts
    Member since:
    Mar 2010

    Posted 25 Jan 2012 Link to this post

    Hello,

    Thanks for the quick reply. Indeed, after searching for some hours, I've found that in the specific case of my kind of project (Silverlight Business Application), in order for the images to be displayed on the client side, they have to be in the "ClientBin" folder.

    Indeed the problem was the wrong path to the file... Just a thought, shouldn't an exception be raised when having an image pointing to something that doesn't exist?

    Thanks in advance
  4. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 25 Jan 2012 Link to this post

    Hello Fernando,

    The Silverlight platform itself would not raise an exception. RadGridView just uses the Silverlight image control thus having the same behavior.

    Regards,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top