This is a migrated thread and some comments may be shown as answers.

Problem showing images with GridViewImageColumn

3 Answers 196 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Fernando Real
Top achievements
Rank 1
Fernando Real asked on 24 Jan 2012, 06:34 PM
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

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 25 Jan 2012, 08:05 AM
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 >>

0
Fernando Real
Top achievements
Rank 1
answered on 25 Jan 2012, 12:34 PM
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
0
Pavel Pavlov
Telerik team
answered on 25 Jan 2012, 01:34 PM
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 >>

Tags
GridView
Asked by
Fernando Real
Top achievements
Rank 1
Answers by
Maya
Telerik team
Fernando Real
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or