Resource "ImageConverter" cannot be resolved

I am new to developing Windows phones and Silverlight. During my teachings, I encountered an error that I mentioned in the title of this post.

My main goal is to save and extract the image file to the SQLCE database, and I used this tutorial http://antonswanevelder.com/2011/10/28/writing-an-image-to-sql-ce-linq-to-sql /

However, I had a problem with this piece of code

<Image Source="{Binding ItemImage, Converter={StaticResource ImageConverter}}" Stretch="UniformToFill"/>

My idea is that the compiler cannot find the resulting ImageConverter. I really need help with this.

My code: MainPage.xaml

 <phone:PhoneApplicationPage.Resources> <DataTemplate x:Key="CallListListBoxItemTemplate"> <StackPanel Orientation="Vertical"> <TextBlock Text="{Binding CallName}" Foreground="DarkCyan" FontSize="{StaticResource PhoneFontSizeLarge}" VerticalAlignment="Top" Margin="12,12,0,0"/> </StackPanel> </DataTemplate> <DataTemplate x:Key="PersonalInfoListBoxItemTemplate"> <Grid > <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Image Source="{Binding PersonImage, Converter={StaticResource ImageConverters}}" Stretch="UniformToFill" Name="_personPhoto" /> 

MainPage.xaml.cs

 public class ImageConverters : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is byte[]) { MemoryStream ms = new MemoryStream(value as byte[]); WriteableBitmap wb = PictureDecoder.DecodeJpeg(ms, 100, 100); return wb; } else { return null; } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } 
+4
source share
1 answer

Consider your value converter in the ProjectName.Converters namespace.

In xaml you need to add a namespace:

 <phone.PhoneApplicatinPage .. all your code here xmlns:converters="clr-namespace;ProjectName.Converters" > 

and in the Resources tag:

  <phone:PhoneApplicationPage.Resources> <converters:ImageConverters x:Key="ImageConverter"/> <!- your DataTemplates here--> 

And a little tutorial to introduce you to IValueConverter here

+7
source

Source: https://habr.com/ru/post/1442496/


All Articles