I m loading an image path from isolated storage settings in my application.
[DataMember]
public string entryImage = "";
[DataMember]
public string EntryImage
{
get { return entryImage; }
set { entryImage = value; }
}
using a helper class to store the image into isolated storage file.
public static void SaveImage(Stream imageStream, string directory, string filename)
{
try
{
string path = System.IO.Path.Combine(directory, filename);
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isoStore.DirectoryExists(directory)) isoStore.CreateDirectory(directory);
using (var writeStream = isoStore.CreateFile(path))
{
byte[] buffer = new byte[32768];
while (true)
{
int read = imageStream.Read(buffer, 0, buffer.Length);
if (read <= 0)
return;
writeStream.Write(buffer, 0, read);
}
}
}
}
// Catch exception if unable to save the image
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Here is the part where I store the imagepath to observablecollection
MyDiaryItem _saveItems = new MyDiaryItem();
_saveItems.EntryNotes = InputText.Text;
_saveItems.EntryDate = date.ToString();
_saveItems.EntryImage = AppHelper.ImageDirectory + AppSettings.ImageFilename;
Where MyDiaryItem is the observable collection
public ObservableCollection<MyDiaryItem> diaryItems = null;
Isolated storage save and load
void LoadSettings()
{
if (settings.Contains("DiaryItems"))
{
diaryItems = new ObservableCollection<MyDiaryItem>((List<MyDiaryItem>)settings["DiaryItems"]);
}
}
void SaveSettings()
{
//settings["DiaryItems"] = diaryItems.ToList();
if (diaryItems.ToList() != null)
{
settings.Clear();
settings.Add("DiaryItems", diaryItems.ToList());
settings.Save();
}
}
Here is the xaml code for image source
<ListBox toolkit:TiltEffect.IsTiltEnabled="true" Name="AllEntriesList"
Margin="0,0,-12,0"
SelectionChanged="AllEntriesList_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<Image Source="{Binding EntryImage}" Height="100" Width="100" Stretch="Fill" Margin="12,0,9,0" />
<StackPanel Margin="0,0,0,17" Width="350" Height="Auto">
<TextBlock Text="{Binding EntryLocation}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" />
<TextBlock Text="{Binding EntryNotes}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock Text="{Binding EntryDate}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I want to some how use the imagepath retrived from isolated storage to display the image in the diaryitems list.
I m loading all the diaryitems in my OnNavigatedTo function like this.
AllEntriesList.ItemsSource = app.diaryItems;
I can see the image name populated properly in the diaryItems list. I want to display the image in the diaryItems list. How to do that ?