Now in my MainView.xaml

 <Image Grid.Row="1" Source="{Binding Path=map.MapImage}"></Image> 

And in MapViewModel.cs

 public BitmapImage MapImage { get { return Map.MapComb; } set { Map.MapComb = value; OnPropertyChanged("MapImage"); } } 

The code works as it should (but I don’t need it), I can stuff any image file in MapImage and it will be displayed on the form.

A need in MapViewModel.cs

 public Image MapImage //System.Drawing.Image { get { return Map.MapComb; } set { Map.MapComb = value; OnPropertyChanged("MapImage"); } } 

What should be in MainView.xaml ? Accepted option with edits in MapViewModel.cs and anywhere. MAIN draw a picture from a variable on the form, without saving it anywhere on the disk.

PS: I try to make MVVM application.

  • Still. If you have a map, as I understand it, look at the xamlmapcontrol.codeplex.com project. They have a class TileLayer, see the implementation. - RusArt
  • @RuslanArtamonov would love to get acquainted with this solution. But I could not find the code. Or a description of the principle on which the XAML Map Control is built. Poke a finger if you can. - Ilya
  • The code is there scattered. Specifically about loading tiles - RusArt

2 answers 2

Use the Source property. For example, in the View code, you can do this:

 Children.Add(new Image { Source = bmp }); 

where bmp type ImageSource . You can create it from an array of bytes. For example:

 byte[] array; .... BitmapImage bmp = new BitmapImage(); var ms = new MemoryStream(array); bmp.BeginInit(); bmp.StreamSource = ms; bmp.EndInit(); 
  • The string var ms = new MemoryStream(array); . Got an idea. How did I write in the question. But there was a new question. - Ilya

With System.Drawing.Image will not work, since WPF only works with classes like System.Windows.Media.ImageSource . You can write a converter that will turn System.Drawing.Image into System.Windows.Media.Imaging.BitmapImage , but this is probably not necessary. You should in the place where you get your picture, receive it immediately in the correct format.

  • Actually, what I expected - that will be incomprehensible what I want. Let me explain: the pictures are downloaded from the Internet and collected into one, and then displayed (this is a map). And of course you can go to different points of the map. Thought to issue <Image Source="{Binding Path=map.MapImage}"></Image> . But in this case, you need to create exactly as many pictures as you flip through the card (if I don’t cache BitmapImage, then I get an exception, if I cache, the picture doesn’t change). - Ilya
  • @ Ilya: Well, well, the pictures you downloaded, but where did System.Drawing.Image come from? - VladD
  • @ Ilya: The phrase “if I don’t cache BitmapImage, then I’m getting an exception, if I cache, the picture doesn’t change” I didn’t understand. An exception indicates that you have made a mistake somewhere, and not that you cannot cache. - VladD
  • @ Ilya: And in your question it says “not saving to disk”. And then save to disk? ImageSource can be obtained without saving. - VladD
  • one
    @ Ilya: Look here: ru.stackoverflow.com/q/584555/10105 - VladD