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

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 に答える
0

Imageタイプpropertyuを使用する代わりに、このようにinを与えることbindで直接できます--->imagepathImage Source

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

パス (文字列型) u が設定および取得できる場所

public String path
{
    get;
    set;
}
于 2013-05-13T11:40:04.673 に答える