I used below codes to retrieve image files from LocalFolder
Total images files is 20 in LocalFolder
The problem:
- Only 8 images are displayed and the rest is blank.
Why the rest can not be displayed?
Can bind the BitmapImage file to the image Control as below base on MVVM ?
Example : imageURL ="ms-appdata:///local/imgfile.jpg"
---- In XAML : PhotoView.xaml
<Image x:Name="Img" Source="{Binding ImageUrl}" Stretch="UniformToFill"/>
<TextBlock FontSize="23" Text="{Binding Unit_Price}" Height="23" Margin="3,1,3,0"/>
<TextBlock FontSize="23" Text="{Binding Description}" Height="23" Width="300" Margin="1,1,1,0/>
--- In code behind: PhotoView
ItemsViewModel itemsViewModel = null;
ObservableCollection items = null;
itemsViewModel = new ItemsViewModel();
items = itemsViewModel.GetItems();
//-- GridViewControl
ItemsViewSource.Source = items;
ItemsGridView.SelectedItem = null;
-------------MVVM
--------- Model :
class ItemViewModel : ViewModelBase
{
private string imageurl = string.Empty;
public string ImageUrl
{
get
{ return imageurl; }
set
{
if (imageurl == value)
{ return; }
imageurl = value;
isDirty = true;
RaisePropertyChanged("ImageUrl");
}
}
private decimal unit_price = 0;
public decimal Unit_Price
{
get
{ return unit_price; }
set
{
if (unit_price == value)
{ return; }
unit_price = value;
isDirty = true;
RaisePropertyChanged("Unit_Price");
}
}
}
---------- View Model
class ItemsViewModel : ViewModelBase
{
private ObservableCollection items;
public ObservableCollection Items
{
get
{
return items;
}
set
{
items = value;
RaisePropertyChanged("Items");
}
}
public ObservableCollection GetItems()
{
items = new ObservableCollection();
using (var db = new SQLite.SQLiteConnection(App.DBPath))
{
var query = db.Table().Where(c=> c.CompanyName == Company).OrderBy(c => c.No);
foreach (var _item in query)
{
var item = new ItemViewModel()
{
No = _item.No,
ImageUrl = "ms-appdata:///local/" + _item.PictureFilename,
Unit_Price = _item.Unit_Price,
Description = _item.Description
};
items.Add(item);
}
}
return items;
}