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

Dynamically Change Image

3 Answers 1052 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 20 Feb 2015, 05:46 PM
I have a telerik report that on the hear I want to display a logo that would co with the client the report is being printed for.  I know if I put the images on a network drive and then in the dataset returned I return the th file location and then

private void reportHeader_ItemDataBinding(object sender, EventArgs e)
{
    this.LogoImage.Value = "=Fields.Logo";
}

this will work.  but I would rather point to a file that is in the resources folder of the project.  This is a WPF project
On the forms of the wpf application I can add
Image1.Source = new BitmapImage(new Uri(@"/Resources/" + c.Logo,UriKind.Relative));

and it gets the logo from my resources folder.  I would like the report to get the image from that same location.







3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 25 Feb 2015, 08:30 AM
Hello Frank,

The supported approaches for setting a PictureBox.Value are listed in the item's overview article. One of them is to use a user function where you can add the logic to retrieve an image from custom location as the application's resources.

Let us know if you need any further help.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Shanthosh
Top achievements
Rank 1
answered on 16 Feb 2019, 11:24 AM

xaml code:

<telerik:RadButton>

 <Image MaxHeight="20" MaxWidth="20" Source="{Binding Converter={StaticResource IconConverter}}"></Image>

</telerik:RadButton>

code :

using DataAccess.Model.General;
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace fer.Converter
{
    public class IconConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            GeneralTechnoProjectInfo generalTechnoProjectInfo = (GeneralTechnoProjectInfo)value;
            if (generalTechnoProjectInfo.LockedBy != 0)
            {
                Uri uri = new Uri(@"/fer;component/Images/cut.png", UriKind.Relative);
                BitmapImage image = new BitmapImage(uri);
                return image;
            }
            else
            {
                Uri uri = new Uri(@"/fer;component/Images/UnLock.png", UriKind.Relative);
                BitmapImage image = new BitmapImage(uri);
                return image;
            }
            
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

 

note:

uisng the converter it was working fine but instantly its not changing an image dynamic by click the button.

after it was refresh the page it can working the image dynamic...

jz tel how to use ivalue converter by instantly change an image dynamic

 

 

 

0
Dilyan Traykov
Telerik team
answered on 20 Feb 2019, 01:50 PM
Hello Shanthosh,

Although the original product of this thread is Telerik Reporting, I assume your inquiry is targeted to the UI for WPF suite. Please correct me if I'm wrong in this assumption. In the future, please make sure that you post your queries in the respective forum sections.

I've prepared a small sample project to demonstrate how you can dynamically change the source of an image.

In your particular scenario, I believe you should be able to achieve the desired result by defining your binding and converter like so:

<telerik:RadButton>
    <Image MaxHeight="20" MaxWidth="20" Source="{Binding LockedBy, Converter={StaticResource IconConverter}}"></Image>
</telerik:RadButton>

public class IconConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var lockedBy = (int)value; // if the type of LockedBy is not int, replace this accordingly
        if (lockedBy != 0)
        {
            Uri uri = new Uri(@"/fer;component/Images/cut.png", UriKind.Relative);
            BitmapImage image = new BitmapImage(uri);
            return image;
        }
        else
        {
            Uri uri = new Uri(@"/fer;component/Images/UnLock.png", UriKind.Relative);
            BitmapImage image = new BitmapImage(uri);
            return image;
        }
 
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

With this setup, provided that the GeneralTechnoProjectInfo correctly implements the INotifyPropertyChanged interface, once the LockedBy value of the bound object changes, the image should update as expected.

Please let me know if this works for you.

Regards,
Dilyan Traykov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Frank
Top achievements
Rank 1
Answers by
Stef
Telerik team
Shanthosh
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or