Binding RadMosaicHubTile ImageSources

14 posts, 1 answers
  1. Daniel Grünberger
    Daniel Grünberger avatar
    46 posts
    Member since:
    May 2008

    Posted 23 Apr 2012 Link to this post

    Hi,

    I'm using the HubTiles in an MVVM environment.

    I'd like to bind the ImageSources Property of the RadMosaicHubTile to a list of strings, to have different pictures shown when having different data. Unfortunately the ImageSources can't be bound. Is there an other approach for this?

    Greets
  2. Answer
    Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 24 Apr 2012 Link to this post

    Hello David,

    Currently this scenario is not supported. You will have to manually insert the strings inside the ImageSources property. Sorry for the inconvenience caused.

    Kind regards,
    Kiril Stanoev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 24 Apr 2012 Link to this post

    Hi David,

     A quick follow up on the matter. I've discussed your scenario with our development team and binding the ImageSources property will be available and supported with our next internal build. 

    Greetings,
    Kiril Stanoev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  5. Daniel Grünberger
    Daniel Grünberger avatar
    46 posts
    Member since:
    May 2008

    Posted 25 Apr 2012 Link to this post

    Hi,

    thanks for your answer and the good news. Seems to be the second reason to look forward to downloading a new build ;)

    Greets
  6. Daniel Grünberger
    Daniel Grünberger avatar
    46 posts
    Member since:
    May 2008

    Posted 03 May 2012 Link to this post

    Hi,

    I tried the internal build and the Property is visible in XAML to be bound. However, if I bind the Property to my ViewModel, I receive following error when I initialize the view:

    Value can not be null.
    Parameter name: ImageSources cannot be null.

    What's wrong there?
  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 03 May 2012 Link to this post

    Hello David,

    Thanks for the question.
    This exception is raised by the base of class RadMosaicHubTile (PictureHubTile) because it does not allow the ImageSources property to be set to null. You could avoid this very easily by always returning a valid collection object (it's ok for the collection to empty) from your ViewModel.
    Since this behavior seems to be unfriendly, we will consider modifying PictureHubTile to work with a null collection.

    Please write again if you have other questions.

    Kind regards,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Daniel Grünberger
    Daniel Grünberger avatar
    46 posts
    Member since:
    May 2008

    Posted 03 May 2012 Link to this post

    Hi,

    thanks for your answer.
    It seems to work with an empty collection, but it has to be an ObservableCollection<string>, a standard List<string> Collection will not work, because there seems to be a problem with converting those two.

    It would be definately be helpful if the Control will also work with a null value.

    I'm also quite unhappy with the fact, that I have to provide a Uri for the picture. In my scenario I download the pictures from a Service and as a result I get a byte[] which I convert to ImageSources. Now I can't bind directly to the Collection of ImageSources. I cannot provide an Converter either, because it always needs a string array.
    As a workaround I tried to bind to an Collection of IDs for the images so I can identify them and use a custom CreateImageSource method. But unfortunately I was not able to set the CreateImageSource method from XAML, and I can't bind it in my ViewModel. So I need to break the MVVM pattern by assigning the Method in code.

    So the Control seems not to be very MVVM-friendly. Maybe you can use my feedback to have some enhancements.

    Greets
  9. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 03 May 2012 Link to this post

    Hi David,

    Thank you very much for the feedback.
    We had a really difficult time figuring out what API to create for the image hub tiles. As it turns out, a collection of strings is not the best approach.
    The change to the current API will be very simple and will not introduce a breaking change. We will simply change the ImageSources to be Collection<object> instead of Collection<string>. In this way, users can put whatever they want inside the collection and will be able to convert whatever objects they put inside via the CreateImageSouce callback property which is already present in the latest build. With the new changes you will be able to do this:

    Collection<object> imageSources = new Collection<object>();
    ImageSource image = GetImageFromWeb();
    imageSources.Add(image);
     
    RadMosaicHubTile hubTile = new RadMosaicHubTile();
    hubTile.CreateImageSource = (source) =>
    {
        return (ImageSource)source;
    };
    hubTile.ImageSources = imageSources;

    Since in your case you directly have ImageSource objects. You just insert them in the ImageSources collection and then set the CreateImageSouce callback to a method that just casts the objects that come from the collection to ImageSource. When CreateImageSource is set back to null, the hub tile will simply assume that the objects are strings and interpret them as such.

    These changes will be in effect in the next internal build.
    Please write again if you need further assistance.

    Kind regards,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  10. Daniel Grünberger
    Daniel Grünberger avatar
    46 posts
    Member since:
    May 2008

    Posted 04 May 2012 Link to this post

    Hi,

    thanks for your reply and also thank you for your change in the API. I will try the new way as soon as the internal build is available.

    Greets
  11. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 07 May 2012 Link to this post

    Hi David,

     I will notify you in this thread as soon as the internal build is available.

    Regards,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  12. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 10 May 2012 Link to this post

    Hello David,

     I am happy to inform you that the new internal build is available. Feel free to try out the new hub tile API :).

    Greetings,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  13. Daniel Grünberger
    Daniel Grünberger avatar
    46 posts
    Member since:
    May 2008

    Posted 16 May 2012 Link to this post

    Hi,

    thanks. I tried it and it works like a charm :) . Thanks for modifying the API.

    Greets
  14. Brian Farnhill
    Brian Farnhill avatar
    1 posts
    Member since:
    May 2010

    Posted 27 May 2012 Link to this post

    Hey guys,

    I ran acorss this one as well and was able to reach a resolution using the latest internal build as well. Any idea when this is likely to make it in to a production release that I can use to publish an update to my app? A rough timeline will do, just to help with the planning on my end.

    Thanks for pushing this fix in as well guys, being able to bind the image source for this control makes much more sense!

    Cheers,

    Brian
  15. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 28 May 2012 Link to this post

    Hi Brian,

    We have not planned any internal builds until the official release which is on June 6th (next week).
    Please write again if you have other questions.

    Kind regards,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner