Dynamically Change Image

4 posts, 0 answers
  1. Frank
    Frank avatar
    99 posts
    Member since:
    Mar 2012

    Posted 20 Feb 2015 Link to this post

    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.







  2. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 25 Feb 2015 Link to this post

    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.

     
  3. Shanthosh
    Shanthosh avatar
    8 posts
    Member since:
    Feb 2019

    Posted 16 Feb in reply to Frank Link to this post

    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

     

     

     

  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    886 posts

    Posted 20 Feb Link to this post

    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
Back to Top