locked
Binding string of image file locations to an image control in desktop app. RRS feed

  • Question

  • I'm new to Lightswitch. I've been evaluating it for about 2 weeks now and thought that a good way to dive in is to try to replicate the functionality of an MS Access project that uses SQL Server on the backend. 

    I have a table of image file locations used for a product catalog. These are not blob fields but rather nvarchars that hold the filename and path to the images. I thought it would be a simple matter of providing the file location field as a string to an image control so it could display thumbnails in a grid for a desktop app. It looks like it can be easily done with an HTML client app (although I have not tried) but I've run up against a brick wall trying to bind the built-in image control to a string property of an entity that points to local and network files.

    I'm not a silverlight developer so building a custom control would be a lot of work since the ramp up time to be productive would be considerable.

    Am i missing something obvious or is my only option a custom silverlight control? So far I'm realy liking Lightswitch especially since it makes building multi-tier apps so quick and easy. I'm even been considering using it solely for creating oData services, since its so simple, and consuming them from traditional winforms or asp.net apps that I've been writing since forever!

    Thanks,
    Stef.

    Wednesday, May 1, 2013 4:31 AM

All replies

  • I'm not a silverlight developer so building a custom control would be a lot of work since the ramp up time to be productive would be considerable.

    Hi,

    it does not matter, I was not a silverlight developer too, but you can become one very easily. creating your own silverlight control for Lightswitch is very easy indeed. I would recommend reading Michael Washingtons books. On his page LightSwitch Help Website you can also find many very good tutorials, that explain how to make your own Usercontrol.

    what you need is a class UriToBitmapConverter that implements IValueConverter.

    you can find an example here:

    ImageSource aus ByteArray

    you even do not need the memorystream, just use

    new BitmapImage(new Uri(pathtothepicture))

    regards

    Oliver


    Wednesday, May 1, 2013 8:52 AM
  • Hello,

    Depending on how you set up your LS app, you may run into a problem in that the app runs from a web server, and so does not necessarily know about file paths, even network ones. It will expect to grab all of its data from the server.

    If you can make the images available via the server, then displaying them would be very easy with the web image viewer in my custom controls for Lightswitch (see link below). This was designed to allow you to bind it to a property containing the URI for the image, and it displays the image loaded form that URI. I haven't tried it with a network path, but you might like to have a go at that as well.

    Hope this helps.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Wednesday, May 1, 2013 9:03 AM
  • Hi Mr Yossu,

    I am really a fan of Pixata Controls :) very good work, and all the explanations on your homepage too.

    I thought about to mention it, but I tried it with "Pixata Static Image Viewer" and "Pixata Web Image" it did not support the path from my harddisk. Maybe it would be an idea to implement one like "Pixata Harddisk-Image Viewer".

    regards

    Oliver

    Wednesday, May 1, 2013 9:32 AM
  • It's a nice idea, but unfortunately, Silverlight doesn't support loading data from network paths, so I couldn't do it. That's why I suggested adding a virtual directory to the web site that holds the LS app, and making the URIs relative to that.

    The other thought that sprang to mind after posting was that you could add an entity to your model for the images, and intercept the query on the server, and load the data into the entity. As the server project is a plain .NET one, and has access to the network, this would be fairly easy. Then the client would see the data as a property on the entity, and you could use the normal image viewer.

    Hope this helps


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Wednesday, May 1, 2013 1:19 PM
  • Thank you both for you responses. I will dig a little deeper into custom control development but its a struggle to find the time, as I'm sure many are in the same position.

    Mr. Yossu, this is strictly a desktop app not to be run from inside a browser. It is an image manager allowing you to assign images to products as they are shot on the retail room floor. Not unlike a highly simplified version of ACDSee or Lightroom for managing a large number of photos. Item entry is done by one staff member while another shoots photos of incoming new arrivals. The photos get dumped into a folder where some pre-editing is done like cropping, colour correction brightness, etc. So now they have a folder of about 200 to 300 new photos daily. I wrote an MS Access front end that reads the contents of that folder, displays them as thumbnails in a gallery where you can simply point and click to assign to newly entered inventory items. It all local/network file access.  Once that is done, it uploads the images to the live running site and creates/updates catalog entries with descriptions, prices, promos etc. 

    This was surprisingly easy to do with Access 2007.  Hard for me to believe that a Lightswitch application built exclusively for the desktop cannot access local resources like files. I did try to use your image custom control that bind to a URI but without success.  Your controls are great and I would love to see that image control of yours be able to use local files to display images.

    However, this seems like an obvious feature that the built in image viewer control should support natively. As an example, the image control in MS Access will either bind to a BLOB field containing the bitmap data or accept a string pointing to a URL or local/network file.

    Thanks again for taking the time to contribute your ideas.

    Stef Cancelli

    Wednesday, May 1, 2013 2:47 PM
  • Hi Stef,

    I understand your point, but you have to understand that Lightswitch is not a new version of Access :)

    Although there are some similarities, and you can do pretty much anything with LS that you could do with Access, one fundamental difference is that Access is a desktop application, whereas a LS app, whatever topology you choose is a Silverlight client-server app (ignoring the new HTML client for the moment). You may not see the server, but it's still there, and you are still bound by the restrictions of Silverlight, which prevent access to the file system.

    So, I think my second suggestion would be the best. Add an entity for the image, and intercept the query when it's created, pull the images from the file system and put the data in the entity.

    Hope this helps


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Wednesday, May 1, 2013 4:10 PM
  • Hi Stef and Mr Yossu,

    >still bound by the restrictions of Silverlight, which prevent access to the file system.

    i do not agree with you in this Point.

    it's possible to load the Images on the fly from your harddisk by using just the pathfilename to it.

    there is only one hint one must know:

    in Windows you have pathes separated with "\"-backslashes but the Uri wants to have normal "/"-slashes. so just replacing the "\" with "/" and you get the job done.

    OK, unc-pathes like \\Server\public\Pictures\ will still fail to work. but you could of course map the Server drive to a local drive letter, keeping in mind that you may have to convert the pathes in your database by replacing the servername with the drive letter.

    @Stef do you want to have a detailed description and the converter class :)

    Friday, May 10, 2013 10:18 AM
  • description:

    IValueConverter, BytesToBitmapConverter

    the class UriToBitmapConverter

    Public Class UriToBitmapConverter : Implements IValueConverter
        Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object _
            Implements IValueConverter.Convert
            If value Is Nothing OrElse Not (TypeOf value Is String) Then Return Nothing ' Throw New ArgumentException("Illegal argument: ", "value must be of type String")
            Dim v As String = DirectCast(value, String).Replace("\", "/")
            Return New BitmapImage(New Uri(v))
        End Function
        Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object _
            Implements IValueConverter.ConvertBack
            Throw New NotImplementedException
        End Function
    End Class
    

    regards

    Oliver

    Friday, May 10, 2013 12:46 PM
  • Hi Stef and Mr Yossu,

    >still bound by the restrictions of Silverlight, which prevent access to the file system.

    i do not agree with you in this Point.

    Feel free to disagree, but please do so with verified facts, instead of adding irrelevant points as you do below...

    it's possible to load the Images on the fly from your harddisk by using just the pathfilename to it.

    Yes, to a limited extent, which is what I pointed out right at the beginning of this discussion. However, there are some major caveats, which you have conveniently chosen to ignore.

    there is only one hint one must know:

    in Windows you have pathes separated with "\"-backslashes but the Uri wants to have normal "/"-slashes. so just replacing the "\" with "/" and you get the job done.

    This is irrelevant to the question, and is not the one hint you must know, it's a minor point that still misses the main issue being discussed here.

    OK, unc-pathes like \\Server\public\Pictures\ will still fail to work.

    Given that this was actually the specific question that was being asked, I don't see how you can just throw it in as if it were a side issue.

    No-one has questioned the ability of Silverlight to access the local hard drive, but as pointed out before, this is only for special folders such as My Documents (and not UNC paths), it's also only for OOB applications, and it's only when running with elevated security.

    but you could of course map the Server drive to a local drive letter, keeping in mind that you may have to convert the pathes in your database by replacing the servername with the drive letter.

    Actually no. As mentioned before, you can only access special folders, and that does not include root drives. You would have to map the server folder to a subfolder of My Documents (or similar), which again, is what I mentioned earlier in this discussion.

    @Stef do you want to have a detailed description and the converter class :)

    Please read threads carefully before responding in future. You haven't actually addressed any of the specific problems that the original question raised, and have given the impression that the advice offered so far was wrong.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Sunday, May 12, 2013 1:41 PM
  • Hi Mr Yossu,

    it was not my intention to bother you at all.

    please keep in mind that i am not a native english Speaker, but people in the forums are from all over the world.

    instead i unterstood the question having two directions.

    The technical part that you pointed out very precise, with user right restrictions and problems with web applications.

    the second part was more on the side . . . let me use some words of the questioner

    >I will dig a little deeper into custom control development but its a struggle to find the time,

    >as I'm sure many are in the same position

    as for me, I was just glad to solve the problem albeit partially and wanted to share my solution for the forum members and future questions.

    Sorry for the misunderstanding in my words, my intention was just to be helpful.

    Kind regards

    Oliver

    Tuesday, May 14, 2013 9:26 AM
  • Hi Oliver,

    Your English is a lot better than my Spanish, so don't worry about that! You didn't bother me at all, I hope I didn't give the wrong impression with my reply. I was just trying to make it clear that what the original poster wanted to do wasn't possible the way you were suggesting.

    Anyway, we'll see if Stef comes back with any comments.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Friday, May 17, 2013 2:32 PM
  • Hi Mr. Yossu, Oliver, et al..

    I've been reading your posts and experimenting here and there. It has been very enlightening. I did not want to post glib and uninformed comments here as I said, I am not a silverlight developer. 

    I didn't realize that a Lightswitch desktop app was in fact, a silverlight app. It makes sense and I can understand why this architecture was chosen. Being able to create a model and generate a multi-tier solution that targets both the desktop and a browser seems to be much simpler using Silverlight as the common denominator. I understand now why it took a while to  introduce the HTML client component. It has no ties to Silverlight.

    It was the introduction of the HTML client that got me to have a serious look at lightswitch for LOB app development. But I have to be honest, I think the definition of a LOB app is too narrow for modern requirements. Silverlight, as great as it appears to be, has limitations in accessing local resources at least that make it a show stopper for me.

    Its not unreasonable to assume that even a LOB desktop app may require access to the whole file system, UNC paths and network shares. Access and management of digital assets such as media, documents and other files are spec'd out in many programs that I create for my clients.  A multi-tier solution that created a winforms presentation layer would have been perfect, IMHO. The HTML client looks like the right direction, i only wish that same architecture would have been applied to the client side desktop app. 

    I may still use Lightswitch for HTML client apps, but frankly I could just as easily use MVC or an MVVP pattern for that. Since I am still left with creating winforms desktop app, I'm not seeing a big advantage of using Lightswitch.

    Am I missing something obvious? I'd like to wrong on this.

    Regards,

    Stef Cancelli

    Friday, May 17, 2013 5:36 PM
  • I understand now why it took a while to  introduce the HTML client component. It has no ties to Silverlight.

    Actually, I don't think that was the reason for the delay. Lightswitch itself is written using MVVM, so the presentation layer is separate from the rest, making it relatively easy to swap the Silverlight client for anything else.

    Silverlight, as great as it appears to be, has limitations in accessing local resources at least that make it a show stopper for me.

    Well, as I pointed out in my first reply, you may still be able to use it, depending on how your arrangement is set up. Silverlight can access the My Documents folder, so if your images live in there, you shouldn't have any problems.

    I'm not completely clear on exactly what you're trying to do, so I can't give specific guidance, but I woudl be surprised if this issue prevents you from using Lightswitch altogether.

    Its not unreasonable to assume that even a LOB desktop app may require access to the whole file system, UNC paths and network shares.

    Bear in mind that (AFAIK) Silverlight was originally developed as a competitor to Flash. It was a browser plug-in, to enable rich interaction on web sites. Using it fro LOB apps wasn't part of the original spec. They had to add the security features for the web side of things, and we are stuck with them for OOB apps.

    I forgot to mention that you can sign your OOB apps, and have them run with elevated trust. As I remember, that allows full access to the file system, in which case you should be OK. I can't remember details off the top of my head, but if you do a bit of searching around, you should find plenty of info on this.

    The HTML client looks like the right direction, i only wish that same architecture would have been applied to the client side desktop app. 

    Remember that scripts on an HTML page are only limited by what the host browser allows it to do. Silverlight has its own level of security on top of that. Can't really compare the two.

    I may still use Lightswitch for HTML client apps, but frankly I could just as easily use MVC or an MVVP pattern for that. Since I am still left with creating winforms desktop app, I'm not seeing a big advantage of using Lightswitch.

    Remember that Lightswitch is fundamentally a database-driven system. It was designed to give RAD forms-over-data development. You're pushing it to something else. That doesn't mean you can do it, but you are moving out of its original boundaries, so will inevitably run into some issues at first.

    I would investigate the elevated trust OOB option, as that should give you access to the file system. If that's your only blocking point at the moment, then you should be able to get moving. You'll find that the amount of time LS saves you will be well worth the effort!

    Hope this helps

    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    • Marked as answer by Angie Xu Thursday, June 6, 2013 12:08 AM
    • Unmarked as answer by Yann DuranModerator Thursday, June 6, 2013 10:38 AM
    Sunday, May 19, 2013 2:35 PM