locked
Which path format to use to reference image files in LocalFolder

    Question

  • I stored all images in LocalFolder and I need to reference them but not sure which is the correct path format :

    1) ms-appdata:///local/

    2) ms-appdata://local/

    3) ms-appdata://imagfilename.jpg

    ImageUrl = "ms-appdata:    "

    -- In XAML :

     <Image  Source="{Binding ImageUrl}"  Stretch="UniformToFill"/>

    Tuesday, March 18, 2014 3:53 AM

Answers

All replies

  • The first. See the ms-appdata documentation for details.
    Tuesday, March 18, 2014 5:51 AM
    Owner
  • I used below codes to retrieve image files from LocalFolder and the above ms-appdata path to display.

    Total images files is 20 in LocalFolder and the file size is small. 300x300.

    The problem:

    1. Only 8 images are displayed and the rest is blank. What happen to the rest? Why they can not be displayed?


    Can bind the BitmapImage file to the image Control as below?

    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<ItemViewModel> 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<ItemViewModel> items;

            public ObservableCollection<ItemViewModel> Items
            {
                get
                {
                    return items;
                }

                set
                {
                    items = value;
                    RaisePropertyChanged("Items");
                }
            }

     

      public ObservableCollection<ItemViewModel> GetItems()
      {
         items = new ObservableCollection<ItemViewModel>();

         using (var db = new SQLite.SQLiteConnection(App.DBPath))
         {

           var query = db.Table<Item>().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;
      }

    Tuesday, March 18, 2014 7:00 AM
  • If some work and others don't then the problem isn't likely to be the naming scheme in general.

    What are the differences between the files that work and the ones that don't? Can you share a minimal sample that demonstrates the problem on your OneDrive?

    --Rob

    Tuesday, March 18, 2014 9:20 PM
    Owner