Convert Text to Image using IValueConverter

4 posts, 0 answers
  1. Keerthy
    Keerthy avatar
    6 posts
    Member since:
    Feb 2011

    Posted 19 Dec 2011 Link to this post

    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;

     

    }

    }

  2. caroline
    caroline avatar
    1 posts
    Member since:
    Apr 2013

    Posted 07 Apr 2013 Link to this post

    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.
  3. DevCraft banner
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Apr 2013 Link to this post

    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.

  5. Arron
    Arron avatar
    22 posts
    Member since:
    Apr 2013

    Posted 17 Apr 2014 in reply to caroline Link to this post

    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.

    Hi, caroline.
    I wonder have you ever tested its trial package or not? Did it work well in VB.NET platform?



    Best regards,
    Arron
Back to Top