Forum Cross Platform with Xamarin

Load XAML interface from the sql server database?

Good afternoon, I'm new using Xamarin Forms.

I want to know if I can load the XAML view from my database

From the result of a query to a database I would like to raise the entire interface. I explain

I have a table which contains the following attributes:

ID int
Name_Element nvarchar(MAX)
Text nvarchar(MAX)
Placeholder nvarchar(MAX)
Visible Boolean

Which is filled as follows:

ID Name_Element Text Placeholder Visible
1 Label Nombre NULL 1
1 Entry NULL Jean 1
1 Label Apellido NULL 1
1 Entry NULL Ritz 1

From the result of the query, from the previous table I would like to show in my app the 4 elements the Label with its entry.

I fully understand that in the XAML file binding is used to assign some properties, however apart from assigning properties, I also want to define what type of element is (Label, Entry, DatePicker, etc).

I am looking forward to your response.
Thank you very much

Posts

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Could you? Yeah, it could be done.
    Would I want to do it? Oh heck no.

    What is your real final goal? Not the technique you're trying to use to get there (through the DB)? But the reason you're trying this.

  • Dev_Jr2018Dev_Jr2018 Member ✭✭

    @ClintStLaurent said:
    Could you? Yeah, it could be done.
    Would I want to do it? Oh heck no.

    What is your real final goal? Not the technique you're trying to use to get there (through the DB)? But the reason you're trying this.

    Good morning,

    I'm trying to do is load the interface dynamically through the information contained in DB, ie a generic interface which may vary depending on the info. contended in the DB.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    But why is the question. Why that weird approach of getting them from a DB instead of accepted practices and patterns that WPF developers have used for XAML layouts for 15-ish years?
    If you can pre-make the layout in order to put it in the db then you can put it in the app.

    If you just want a dynamic layout that corresponds to your data, XAML is pretty flexible. It will expand to list multiple items, hide areas if they don't apply, you can specify ControlTemplates to apply based on run-time data.

  • Dev_Jr2018Dev_Jr2018 Member ✭✭

    @ClintStLaurent said:
    But why is the question. Why that weird approach of getting them from a DB instead of accepted practices and patterns that WPF developers have used for XAML layouts for 15-ish years?
    If you can pre-make the layout in order to put it in the db then you can put it in the app.

    If you just want a dynamic layout that corresponds to your data, XAML is pretty flexible. It will expand to list multiple items, hide areas if they don't apply, you can specify ControlTemplates to apply based on run-time data.

    The client that requested it asked me to do so because he does not want to touch the code after having his application, simply enter the database and add a record for example of type label and show it.

    I also find it a bit strange.

    It should be noted that reading your previous comment you recommend that you put many types of elements in the code of XAML or define the default and with the property "visible" show or not, from a value that brings me from the database?

    Thanks for your reply and sorry for the inconvenience.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    record for example of type label and show it.

    Just weird. Sounds like someone trying to build reports off line, then download them to the device.
    Yeah, I guess it can work. Like I said before you can do it. Its not syntactically impossible or anything. I just wouldn't want to be a part of that project and by extension part of the client's company if that's how they work.

    It should be noted that reading your previous comment you recommend that you put many types of elements in the code of XAML or define the default and with the property "visible" show or not, from a value that brings me from the database?

    Sort of. Its not uncommon to add a XAML block for the details of... The person's car, and then hide that block if the person doesn't have a car. If the person doesn't have a spouce, then don't show the SpouceControlView

  • MommMomm USMember ✭✭✭

    @Dev_Jr2018, Some options:

    • Not use XAML in your case, at least for this part and use code behind to add the elements.
    • You can get all of the elements from the DB, add it to an ObservableCollection, set it to a ListView and then use a TemplateSelector to create each template that you want (Entry, Label, etc).

    Please let me know if it helps.

  • Dev_Jr2018Dev_Jr2018 Member ✭✭

    @Momm said:
    @Dev_Jr2018, Some options:

    • Not use XAML in your case, at least for this part and use code behind to add the elements.
    • You can get all of the elements from the DB, add it to an ObservableCollection, set it to a ListView and then use a TemplateSelector to create each template that you want (Entry, Label, etc).

    Please let me know if it helps.

    Thanks!!

  • Dev_Jr2018Dev_Jr2018 Member ✭✭

    @ClintStLaurent said:

    record for example of type label and show it.

    Just weird. Sounds like someone trying to build reports off line, then download them to the device.
    Yeah, I guess it can work. Like I said before you can do it. Its not syntactically impossible or anything. I just wouldn't want to be a part of that project and by extension part of the client's company if that's how they work.

    It should be noted that reading your previous comment you recommend that you put many types of elements in the code of XAML or define the default and with the property "visible" show or not, from a value that brings me from the database?

    Sort of. Its not uncommon to add a XAML block for the details of... The person's car, and then hide that block if the person doesn't have a car. If the person doesn't have a spouce, then don't show the SpouceControlView

    Thanks!!

Sign In or Register to comment.