Bug 17892 - MT.D Can't assign an image to a StringElement or StyledStringElement when loading from a JSON file.
Summary: MT.D Can't assign an image to a StringElement or StyledStringElement when loa...
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: 7.0.2.x
Hardware: Macintosh Mac OS
: --- enhancement
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-02-19 15:51 UTC by Jon Goldberger [MSFT]
Modified: 2018-04-14 03:49 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Comment 1 Jon Goldberger [MSFT] 2014-02-19 16:06:06 UTC
Working from the MonoTouch.Dialog sample app.

I see no way to add an image to an element in the .JSON file that is used to load the JSON sample page, nor can I easily add an image to an element after the JSON is loaded since the view has not been created yet, and even once it is created. there is not a way that I can see to modify the elements as the entire interface is created from the JSON file, so there is no DialogViewController class that can be edited in code to modify the Elements once they are displayed.  

I do see that you can add a background image or a BooleanElement on/off image, but not the left aligned image that is part of the UITableViewCell.Default, UITableViewCell.Subtitle, or UITableViewCell.Value1 cell styles that the StringElement or StyledStringElement uses. 

In Main.cs of the sample app, I tried looping through the elements of the Strings section by adding an ID, "stringElements", to the section in the sample.json file with:

// Lookup elements by ID:

var jsonSection = sampleJson ["stringElements"] as Section;
Console.WriteLine ("The section has {0} elements", jsonSection.Count);
foreach (StringElement el in jsonSection) {
    if (el.Caption == "Plain label" || el.Caption == "Plain label with value: " || el.Caption == "Styled label with subtitles") {
        Console.WriteLine("JsonElement: {0}", el.Summary());
    }
}

While the above does get me to the relevant elements created from the sample.json file, there is no image or imageUri property in any of the Element classes that I can use to set an image, and I can't get to the underlying cell to set its image as the cells have not been created yet. 

There very well might be a way to do this that I am unaware of, but it still would be convenient to be able to set an image, or imageUri, in the JSON file just as you can set a background image or BooleanElement image.
Comment 2 Alex Soto [MSFT] 2018-04-14 03:49:07 UTC
You can definitely do this using a string element type for example, using the background property in the JSON definition:

```
{
  "title": "Json Sample",
  "sections": [
    {
      "header": "Strings",
      "elements": [
        {
          "type": "string",
          "caption": "the background color is set",
          "background": "#f0f"
        },
        {
          "type": "string",
          "caption": "Background color set from a URI",
          "background": "https://www.google.com/images/logos/ps_logo2.png"
        }
      ]
    }
  ]
}
```

So the property serves both a hex color and a uri.