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

Convert Text to Image using IValueConverter

3 Answers 188 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Keerthy
Top achievements
Rank 1
Keerthy asked on 19 Dec 2011, 01:34 PM
Hi,
     I have a RadGridView which has two columns - A combobox column and image column. I need to change the image present in the image column based on the change in combobox column.

I have tried the following combination:
XAML :

 

 

 

<UserControl.Resources>

 

 

 

 

<local:Value2ImageURLConverter1 x:Key="GetImageURL"/>

 

 

 

 

</UserControl.Resources>

 


 

 

 

<telerik:RadGridView x:Name="radGrid"

 

 

 

ShowGroupPanel="False"

 

 

 

HorizontalAlignment="Left"

 

 

 

VerticalAlignment="Top"

 

 

 

Margin="20"

 

 

 

Grid.Row="2"

 

 

 

RowIndicatorVisibility="Collapsed"

 

 

 

AutoGenerateColumns="False"

 

 

 

ItemsSource="{Binding RandomAnswersList}"

 

 

 

 

<telerik:RadGridView.Columns>

<

 

 

telerik:GridViewDataColumn Header="Status Image" Width="90" IsReadOnly="True" >

 

 

 

 

<telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<StackPanel Orientation="Vertical">

 

 

 

 

<Image x:Name="img" Visibility="Visible" Source="{Binding Status,Converter={StaticResource GetImageURL}}" Width="100" Height="100"/>

 

 

 

 

<TextBlock Text="{Binding Status}">

 

 

 

 

</TextBlock>

 

 

 

 

</StackPanel>

 

 

 

 

</DataTemplate>

 

 

 

 

</telerik:GridViewDataColumn.CellTemplate>

 

 

 

 

</telerik:GridViewDataColumn>

 

 

 

 

<telerik:GridViewDataColumn Header="Status"

 

 

 

IsReadOnly="True"

 

 

 

DataMemberBinding="{Binding Status}">

 

 

 

 

</telerik:GridViewDataColumn>

 

 

 

 

</telerik:RadGridView.Columns>

 

 

 

 

</telerik:RadGridView>

 


XAML.cs

public

 

 

class Value2ImageURLConverter1 : IValueConverter

 

{

 

 

public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)

 

{

 

 

 

 

string appRoot = Application.Current.Host.Source.ToString().Substring(0, src.IndexOf("ClientBin"));

 

Image image = new Image();

 

 

 

if (value == null)

 

{

 

 

 

 

return new BitmapImage(new Uri(appRoot + "/Images/ExceptionRequest2.PNG", UriKind.RelativeOrAbsolute));

 

}

 

 

else if (value.Equals("Completed"))

 

{

 

 

return new BitmapImage(new Uri(appRoot + "/Images/Completed.PNG", UriKind.RelativeOrAbsolute));

 

}

 

 

else if (value.Equals("Outstanding"))

 

{

image.Source =

 

new BitmapImage(new Uri(appRoot + "/Images/Outstanding.PNG", UriKind.RelativeOrAbsolute));

 

}

 

 

return image;

 

 

 

//if (value != null)

 

//{

 

 

//return "/Images/ExceptionApproved.PNG";

 

//}

 

 

//else

 

 

 

//return "/Images/ExceptionRequest2.PNG";

 

//}

 

 

public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)

 

{

 

 

return null;

 

}

}

3 Answers, 1 is accepted

Sort by
0
caroline
Top achievements
Rank 1
answered on 08 Apr 2013, 01:53 AM
sorry, i donnot know about this, i just know  an image converter. Mature and reliable image conversion software which convert large amout of image at fast speed.
0
Dimitrina
Telerik team
answered on 08 Apr 2013, 11:54 AM
Hello,

When you change the value selected with the ComboBox, then you need to change the value for the "Status" property as well. That way the converter set for the binding will be invoked and you can change the image.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Arron
Top achievements
Rank 1
answered on 17 Apr 2014, 06:58 AM
[quote]caroline said:sorry, i donnot know about this, i just know  an image converter. Mature and reliable image conversion software which convert large amout of image at fast speed.[/quote]
Hi, caroline.
I wonder have you ever tested its trial package or not? Did it work well in VB.NET platform?



Best regards,
Arron
Tags
General Discussions
Asked by
Keerthy
Top achievements
Rank 1
Answers by
caroline
Top achievements
Rank 1
Dimitrina
Telerik team
Arron
Top achievements
Rank 1
Share this question
or