Reputation: 1416
I want bind image from control page to main page but I cannot get it to work. I try this:
XAML: <Image Source="{Binding myImage}" Height="150" Name="photoPreview"...
binding:
public Image myImage
{
get;
set;
}
Some idea here?
Upvotes: 0
Views: 141
Reputation: 1416
More details from my source maybe someone get idea where is problem>
Control page (POPUP)
private void SaveToIsolatedStorage(Stream imageStream, string fileName)
{
using (IsolatedStorageFile myIsoStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsoStorage.FileExists(fileName))
{
myIsoStorage.DeleteFile(fileName);
}
IsolatedStorageFileStream fileStream = myIsoStorage.CreateFile(fileName);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(imageStream);
WriteableBitmap mywb = new WriteableBitmap(bitmap);
mywb.SaveJpeg(fileStream, mywb.PixelWidth, mywb.PixelHeight, 0, 95);
fileStream.Close();
}
this.ReadFromIsolatedStorage("myImage.jpg");
}
private void ReadFromIsolatedStorage(string fileName)
{
WriteableBitmap bitmap = new WriteableBitmap(200, 200);
using (IsolatedStorageFile myIsoStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsoStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read))
{
bitmap = PictureDecoder.DecodeJpeg(fileStream);
}
}
photoPreview.Source = bitmap;
}
public String myNote { get; set; }
public String path
{
get;
set;
}
CONTROL PAGE POPUP XAML
<Image Source = "{Binding Path = path}" Height="150" HorizontalAlignment="Right" Name="photoPreview"
New class for binding named Note.cs
public class Note : INotifyPropertyChanged {
public String myNote { get; set; }
public String path
{
get;
set;
}...
Main page
var note = new Note();
note.myNote = control.myNote;
note.OnPropertyChanged("myNote");
note.path = control.path;
note.OnPropertyChanged("path");
Notes.Add(note);
OnPropertyChanged("Notes");
Main page. xaml
<Image Width="100" Height="100" Stretch="Fill" Source = "{Binding Path = path}"></Image>
P.s binding text myNote from textbox work great but image not.
Upvotes: 0
Reputation: 3966
instead of using Image
type property
u can bind
the image
directly by giving the path
in Image
Source
like this--->
<Image Source = "{Binding Path = path}" Height="150" Name="photoPreview"...
where the path (string type) u can set & get
public String path
{
get;
set;
}
Upvotes: 0
Reputation: 7135
You can't bind an Image
object to the Source
property of an Image control. The Source
property is of type ImageSource
. Use BitmapImage in your code and bind that instead.
public BitmapImage myImage { get; set; }
Or if the image file is included in your project's assets you can bind the relative path as well (as a string).
Upvotes: 1