0

我想将控制页面中的图像绑定到主页,但我无法让它工作。我试试这个:

XAML: <Image Source="{Binding myImage}" Height="150"  Name="photoPreview"...

捆绑:

public Image myImage
{
    get;
    set;
}

这里有什么想法?

4

3 回答 3

1

不能将Image对象绑定到SourceImage 控件的属性。该Source属性的类型为ImageSource。在您的代码中使用 BitmapImage 并绑定它。

public BitmapImage myImage { get; set; }

或者,如果图像文件包含在项目的资产中,您也可以绑定相对路径(作为字符串)。

于 2013-05-12T20:30:30.723 回答
0

而不是使用Image类型propertyu 可以直接通过像这样给出bindin --- >imagepathImage Source

<Image Source = "{Binding Path = path}" Height="150"  Name="photoPreview"...

您可以设置和获取的路径(字符串类型)

public String path
{
    get;
    set;
}
于 2013-05-13T11:40:04.673 回答
0

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.

于 2013-05-13T18:21:01.753 回答