Click here to Skip to main content
15,949,686 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Alisaunder21-Jul-12 12:30
Alisaunder21-Jul-12 12:30 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Mycroft Holmes21-Jul-12 13:52
professionalMycroft Holmes21-Jul-12 13:52 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Alisaunder21-Jul-12 14:59
Alisaunder21-Jul-12 14:59 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Mycroft Holmes21-Jul-12 16:14
professionalMycroft Holmes21-Jul-12 16:14 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Pete O'Hanlon22-Jul-12 21:52
mvePete O'Hanlon22-Jul-12 21:52 
QuestionAdding datagrid cell images at runtime doesn't appear in cell Pin
alleyes20-Jul-12 8:40
professionalalleyes20-Jul-12 8:40 
GeneralRe: Adding datagrid cell images at runtime doesn't appear in cell Pin
Christian Amado21-Jul-12 12:03
professionalChristian Amado21-Jul-12 12:03 
GeneralRe: Adding datagrid cell images at runtime doesn't appear in cell Pin
alleyes22-Jul-12 17:07
professionalalleyes22-Jul-12 17:07 
I found the following as a source of help towards the solution:
C#
public class ImageConverter : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return new BitmapImage(new Uri((string)value, UriKind.RelativeOrAbsolute));
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new System.NotImplementedException();
        }
    }


The path to the image is Images\File.bmp. I tried changing the formatting of the string to create a proper Uri, but the image STILL does not appear in the cell Dead | X|

I found a solution which helped in better creating the path to be in the proper form of a Uri. What follows IS the solution:
C#
public class ImageConverter : IValueConverter
{

    public static BitmapImage CreateBMImage(string path)
    {
        BitmapImage bi = new BitmapImage();

        try
        {
            bi.BeginInit();
            bi.CacheOption = BitmapCacheOption.OnDemand;
            Uri baseUri = new Uri(Application.ResourceAssembly.Location);
            bi.UriSource = new Uri(baseUri, path);
            bi.EndInit();
        }

        catch
        {
            return null;
        }

        return bi;
    }

    public static Image CreateImage(string path)
    {
        Image img = new Image();
        img.Source = CreateBMImage(path);
        return img;
    }

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        try
        {
            return CreateBMImage((string)value);
        }

        catch
        {
            return new BitmapImage();
        }

    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new System.NotImplementedException();
    }
}


modified 23-Jul-12 10:34am.

GeneralUnintended Save Issue WPF Pin
eddieangel20-Jul-12 7:20
eddieangel20-Jul-12 7:20 
GeneralRe: Unintended Save Issue WPF Pin
Ian Shlasko20-Jul-12 7:31
Ian Shlasko20-Jul-12 7:31 
GeneralRe: Unintended Save Issue WPF Pin
eddieangel20-Jul-12 7:37
eddieangel20-Jul-12 7:37 
GeneralRe: Unintended Save Issue WPF Pin
Ian Shlasko20-Jul-12 7:45
Ian Shlasko20-Jul-12 7:45 
GeneralRe: Unintended Save Issue WPF Pin
eddieangel20-Jul-12 7:49
eddieangel20-Jul-12 7:49 
GeneralRe: Unintended Save Issue WPF Pin
Ian Shlasko20-Jul-12 8:16
Ian Shlasko20-Jul-12 8:16 
QuestionButton Style Question Pin
Kevin Marois19-Jul-12 9:21
professionalKevin Marois19-Jul-12 9:21 
AnswerRe: Button Style Question Pin
Wayne Gaylard19-Jul-12 20:15
professionalWayne Gaylard19-Jul-12 20:15 
Questiontip for scrollviewer Pin
caradri18-Jul-12 23:10
caradri18-Jul-12 23:10 
GeneralRe: tip for scrollviewer Pin
Wayne Gaylard18-Jul-12 23:38
professionalWayne Gaylard18-Jul-12 23:38 
GeneralRe: tip for scrollviewer Pin
caradri19-Jul-12 1:16
caradri19-Jul-12 1:16 
GeneralRe: tip for scrollviewer Pin
Mycroft Holmes19-Jul-12 12:48
professionalMycroft Holmes19-Jul-12 12:48 
GeneralRe: tip for scrollviewer Pin
Christian Amado19-Jul-12 17:43
professionalChristian Amado19-Jul-12 17:43 
GeneralRe: tip for scrollviewer Pin
Pete O'Hanlon19-Jul-12 20:20
mvePete O'Hanlon19-Jul-12 20:20 
GeneralRe: tip for scrollviewer Pin
Mycroft Holmes19-Jul-12 23:19
professionalMycroft Holmes19-Jul-12 23:19 
GeneralRe: tip for scrollviewer Pin
Pete O'Hanlon19-Jul-12 23:27
mvePete O'Hanlon19-Jul-12 23:27 
AnswerRe: tip for scrollviewer Pin
Christian Amado20-Jul-12 0:56
professionalChristian Amado20-Jul-12 0:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.