我想要將圖像從控制頁面綁定到主頁面,但是我無法讓它工作。我試試這個:這裏從控制頁面到主頁面的綁定圖像WP7/8
public Image myImage
{
get;
set;
}
一些想法:
XAML: <Image Source="{Binding myImage}" Height="150" Name="photoPreview"...
結合?
我想要將圖像從控制頁面綁定到主頁面,但是我無法讓它工作。我試試這個:這裏從控制頁面到主頁面的綁定圖像WP7/8
public Image myImage
{
get;
set;
}
一些想法:
XAML: <Image Source="{Binding myImage}" Height="150" Name="photoPreview"...
結合?
您不能將Image
對象綁定到Image控件的Source
屬性。 Source
屬性類型爲ImageSource
。在你的代碼中使用BitmapImage,並將其綁定。
public BitmapImage myImage { get; set; }
,或者圖像文件被包含在項目的資產可以綁定的相對路徑,以及(作爲字符串)。的
而是採用Image
型property
ü可以直接通過給予path
在Image
Source
這樣--- bind
的image
>
<Image Source = "{Binding Path = path}" Height="150" Name="photoPreview"...
其中&路徑(字符串類型)U可以設置得
public String path
{
get;
set;
}
thx man好主意,但這裏仍然存在一些問題,因爲圖像沒有綁定。如果我通過斷點路徑chchck它返回null。我在回答中張貼更多信息。也許有人知道問題在哪裏。 – 2013-05-13 18:12:20
從我的來源的更多細節,也許有人會知道哪裏是問題>
控制頁面(彈出)
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;
}
控制頁面POPUP XAML
<Image Source = "{Binding Path = path}" Height="150" HorizontalAlignment="Right" Name="photoPreview"
用於綁定命名Note.cs
公共類注新類: INotifyPropertyChanged {
public String myNote { get; set; }
public String path
{
get;
set;
}...
主頁
var note = new Note();
note.myNote = control.myNote;
note.OnPropertyChanged("myNote");
note.path = control.path;
note.OnPropertyChanged("path");
Notes.Add(note);
OnPropertyChanged("Notes");
主頁。 XAML
<Image Width="100" Height="100" Stretch="Fill" Source = "{Binding Path = path}"></Image>
P.S從文本框的工作很大,但圖像沒有約束力的文本myNote。
thx求助,但它不起作用。我通過相機拍攝照片,然後將其保存到獨立存儲。從隔離區讀取我使用這個... bitmap = PictureDecoder.DecodeJpeg(fileStream); photoPreview.Source = bitmap;但圖像顯示在控制頁面,但我不能綁定到主頁面。 – 2013-05-13 05:19:46
你是如何設置myImage的? – 2013-05-13 05:48:49
photoPreview.Source = bitmap;在這裏我從獨立存儲中加載圖像並在conrol頁面中顯示它。現在我使用公共BitmapImage myImage {get;組; }將圖像從控制頁面綁定到主頁面,但不成功 – 2013-05-13 18:09:11