Hiding data in a Forms element

I want the UI to maintain info about activities like, "The user has clicked this before" (set programatically).

Html5 has a half-supported convention where you can stick arbitrary data in the DOM using data-X attributes.

Does Xamarin forms have a thing where I can just stash something specific to a widget?

Best Answer

Answers

  • Caleb.MorrisCaleb.Morris USMember
    edited December 2015

    The purpose of data-* in HTML5 is to allow configurable Javascript with different HTML as the initial point of data to parse and run. I'm not aware of any convention that uses data-* as a stateful intermediate. This seems like an anti-pattern as you have to be sure the DOM isn't changed by other controllers first.

    Since with Xamarin.Forms you can integrate various design patterns easily, I would suggest looking into one of these (MVC or MVVM) patterns for isolation and mapping data for widgets and the various workflow of your program.

    If you do want to attach the data directly to the Widget, I would suggest subclassing the widget with a data element that you can alter to make use as you described.

  • MicahHooverMicahHoover USMember ✭✭

    That sounds like a narrow interpretation of the data-* attribute, and not very conventional. Anyway, it's just an analogy in case anyone knew how to do something similar in Xamarin forms.

    The immediate purpose is just to implement a cross-platform version of a radio button and keep track of whether it is depressed without checking to see if the image is the depressed or unpressed image. Subclassing might be the best option, but I will probably look at seeing if there is something I can do with dynamic properties.

Sign In or Register to comment.