Loading images source dynamically with IValueConverter

后端 未结 1 917
再見小時候
再見小時候 2020-12-21 07:24

I\'ve problems with IValueconverter and dynamically load a row grid image:

public object Convert(object value, Type targetType, object parameter, System.Glob         


        
1条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 07:30

    If you create the URI in code you have to write the full Pack URI including the pack://application:,,, part. In XAML this is not necessary as it is automatically added by the string-to-ImageSource TypeConverter.

    var type = (string)value;
    var uri = new Uri("pack://application:,,,/XConsole;component/Images/" + type + ".png");
    

    Note that the above code sample uses a lowercase type identifier instead of Type to avoid confusion with the Type class.

    0 讨论(0)
提交回复
热议问题