How can I create a XAML template that acts as a wrapper for elements?












0














I have this XAML code:



<Frame CornerRadius="1" HasShadow="false" Margin="10" 
BackgroundColor="White" BorderColor="Silver" Padding="0" >
<StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</StackLayout>
</Frame>


Does anyone have any ideas on how I could replace this with something like:



<template:NewFrame>
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</template:NewFrame>


As you can see I'm familiar with how to create and use templates that contain elements, but I don't know how to create a template that I can use as a wrapper for elements.










share|improve this question


















  • 4




    Create custom view that inherits from Frame.
    – Woj
    Nov 21 '18 at 17:59










  • Can you give an example of how to do this.
    – Alan2
    Nov 21 '18 at 18:23










  • follow this one : docs.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/…
    – OrcusZ
    Dec 3 '18 at 12:34










  • One more option you can try. Create different templates in your XAML and depending on the type set that template to your view.
    – K K
    Dec 4 '18 at 10:18
















0














I have this XAML code:



<Frame CornerRadius="1" HasShadow="false" Margin="10" 
BackgroundColor="White" BorderColor="Silver" Padding="0" >
<StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</StackLayout>
</Frame>


Does anyone have any ideas on how I could replace this with something like:



<template:NewFrame>
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</template:NewFrame>


As you can see I'm familiar with how to create and use templates that contain elements, but I don't know how to create a template that I can use as a wrapper for elements.










share|improve this question


















  • 4




    Create custom view that inherits from Frame.
    – Woj
    Nov 21 '18 at 17:59










  • Can you give an example of how to do this.
    – Alan2
    Nov 21 '18 at 18:23










  • follow this one : docs.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/…
    – OrcusZ
    Dec 3 '18 at 12:34










  • One more option you can try. Create different templates in your XAML and depending on the type set that template to your view.
    – K K
    Dec 4 '18 at 10:18














0












0








0







I have this XAML code:



<Frame CornerRadius="1" HasShadow="false" Margin="10" 
BackgroundColor="White" BorderColor="Silver" Padding="0" >
<StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</StackLayout>
</Frame>


Does anyone have any ideas on how I could replace this with something like:



<template:NewFrame>
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</template:NewFrame>


As you can see I'm familiar with how to create and use templates that contain elements, but I don't know how to create a template that I can use as a wrapper for elements.










share|improve this question













I have this XAML code:



<Frame CornerRadius="1" HasShadow="false" Margin="10" 
BackgroundColor="White" BorderColor="Silver" Padding="0" >
<StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</StackLayout>
</Frame>


Does anyone have any ideas on how I could replace this with something like:



<template:NewFrame>
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</template:NewFrame>


As you can see I'm familiar with how to create and use templates that contain elements, but I don't know how to create a template that I can use as a wrapper for elements.







xamarin xamarin.forms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 16:48









Alan2

1,51854132254




1,51854132254








  • 4




    Create custom view that inherits from Frame.
    – Woj
    Nov 21 '18 at 17:59










  • Can you give an example of how to do this.
    – Alan2
    Nov 21 '18 at 18:23










  • follow this one : docs.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/…
    – OrcusZ
    Dec 3 '18 at 12:34










  • One more option you can try. Create different templates in your XAML and depending on the type set that template to your view.
    – K K
    Dec 4 '18 at 10:18














  • 4




    Create custom view that inherits from Frame.
    – Woj
    Nov 21 '18 at 17:59










  • Can you give an example of how to do this.
    – Alan2
    Nov 21 '18 at 18:23










  • follow this one : docs.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/…
    – OrcusZ
    Dec 3 '18 at 12:34










  • One more option you can try. Create different templates in your XAML and depending on the type set that template to your view.
    – K K
    Dec 4 '18 at 10:18








4




4




Create custom view that inherits from Frame.
– Woj
Nov 21 '18 at 17:59




Create custom view that inherits from Frame.
– Woj
Nov 21 '18 at 17:59












Can you give an example of how to do this.
– Alan2
Nov 21 '18 at 18:23




Can you give an example of how to do this.
– Alan2
Nov 21 '18 at 18:23












follow this one : docs.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/…
– OrcusZ
Dec 3 '18 at 12:34




follow this one : docs.microsoft.com/fr-fr/xamarin/xamarin-forms/app-fundamentals/…
– OrcusZ
Dec 3 '18 at 12:34












One more option you can try. Create different templates in your XAML and depending on the type set that template to your view.
– K K
Dec 4 '18 at 10:18




One more option you can try. Create different templates in your XAML and depending on the type set that template to your view.
– K K
Dec 4 '18 at 10:18












2 Answers
2






active

oldest

votes


















1














One way is the one that @Tom said and another one is using a Control template that is basically what you want I think.



Even tough the docs said that




Xamarin.Forms control templates provide the ability to easily theme and re-theme application pages at runtime. This article provides an introduction to control templates




you can use the control template as a wrapper using it in a ContentView (I've done it and it works perfectly).



In your case you'd have to do a ContentView and fill the ContentView.ControlTemplate with your layout of the wrapper:



<ContentView
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:... your namespaces
x:Class="YourNamespace.NewFrame">
<ContentView.ControlTemplate>
<ControlTemplate>
<Frame CornerRadius="1" HasShadow="false" Margin="10"
BackgroundColor="White" BorderColor="Silver" Padding="0" >
<ContentPresenter />
</Frame>
</ControlTemplate>
</ContentView.ControlTemplate>
</ContentView>


As you can see there is a ContentPresenter that is what is going to be replaced with your content (one thing to take into account is that the ContentPresenter allows only one child so you wil have to put your StackLayout inside)



<template:NewFrame>
<StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
<xaml:PtiXaml />
<template:LineTemplate />
<xaml:AtiXaml />
<template:LineTemplate />
<xaml:StiXaml />
</StackLayout>
</template:NewFrame>




Another way would be to do a custom layout but it's more complicated and I wouldn't go that way to do that layout wrapper.






share|improve this answer





























    0














    C#:



    public class CustomFrame : Frame
    {
    public CustomEditor()
    {
    CornerRadius = 1;
    HasShadow = false;
    Margin = 10;
    BackgroundColor = Color.White;
    BorderColor = Color.Silver;
    Padding = 0;
    }
    }


    Usage:



    <template:CustomFrame>
    <StackLayout
    Orientation="Vertical"
    Spacing="0"
    Padding="0" >

    <xaml:PtiXaml />
    <template:LineTemplate />
    <xaml:AtiXaml />
    <template:LineTemplate />
    <xaml:StiXaml />

    </StackLayout>
    </template:CustomFrame>





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416901%2fhow-can-i-create-a-xaml-template-that-acts-as-a-wrapper-for-elements%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      One way is the one that @Tom said and another one is using a Control template that is basically what you want I think.



      Even tough the docs said that




      Xamarin.Forms control templates provide the ability to easily theme and re-theme application pages at runtime. This article provides an introduction to control templates




      you can use the control template as a wrapper using it in a ContentView (I've done it and it works perfectly).



      In your case you'd have to do a ContentView and fill the ContentView.ControlTemplate with your layout of the wrapper:



      <ContentView
      xmlns="http://xamarin.com/schemas/2014/forms"
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
      xmlns:... your namespaces
      x:Class="YourNamespace.NewFrame">
      <ContentView.ControlTemplate>
      <ControlTemplate>
      <Frame CornerRadius="1" HasShadow="false" Margin="10"
      BackgroundColor="White" BorderColor="Silver" Padding="0" >
      <ContentPresenter />
      </Frame>
      </ControlTemplate>
      </ContentView.ControlTemplate>
      </ContentView>


      As you can see there is a ContentPresenter that is what is going to be replaced with your content (one thing to take into account is that the ContentPresenter allows only one child so you wil have to put your StackLayout inside)



      <template:NewFrame>
      <StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
      <xaml:PtiXaml />
      <template:LineTemplate />
      <xaml:AtiXaml />
      <template:LineTemplate />
      <xaml:StiXaml />
      </StackLayout>
      </template:NewFrame>




      Another way would be to do a custom layout but it's more complicated and I wouldn't go that way to do that layout wrapper.






      share|improve this answer


























        1














        One way is the one that @Tom said and another one is using a Control template that is basically what you want I think.



        Even tough the docs said that




        Xamarin.Forms control templates provide the ability to easily theme and re-theme application pages at runtime. This article provides an introduction to control templates




        you can use the control template as a wrapper using it in a ContentView (I've done it and it works perfectly).



        In your case you'd have to do a ContentView and fill the ContentView.ControlTemplate with your layout of the wrapper:



        <ContentView
        xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:... your namespaces
        x:Class="YourNamespace.NewFrame">
        <ContentView.ControlTemplate>
        <ControlTemplate>
        <Frame CornerRadius="1" HasShadow="false" Margin="10"
        BackgroundColor="White" BorderColor="Silver" Padding="0" >
        <ContentPresenter />
        </Frame>
        </ControlTemplate>
        </ContentView.ControlTemplate>
        </ContentView>


        As you can see there is a ContentPresenter that is what is going to be replaced with your content (one thing to take into account is that the ContentPresenter allows only one child so you wil have to put your StackLayout inside)



        <template:NewFrame>
        <StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
        <xaml:PtiXaml />
        <template:LineTemplate />
        <xaml:AtiXaml />
        <template:LineTemplate />
        <xaml:StiXaml />
        </StackLayout>
        </template:NewFrame>




        Another way would be to do a custom layout but it's more complicated and I wouldn't go that way to do that layout wrapper.






        share|improve this answer
























          1












          1








          1






          One way is the one that @Tom said and another one is using a Control template that is basically what you want I think.



          Even tough the docs said that




          Xamarin.Forms control templates provide the ability to easily theme and re-theme application pages at runtime. This article provides an introduction to control templates




          you can use the control template as a wrapper using it in a ContentView (I've done it and it works perfectly).



          In your case you'd have to do a ContentView and fill the ContentView.ControlTemplate with your layout of the wrapper:



          <ContentView
          xmlns="http://xamarin.com/schemas/2014/forms"
          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
          xmlns:... your namespaces
          x:Class="YourNamespace.NewFrame">
          <ContentView.ControlTemplate>
          <ControlTemplate>
          <Frame CornerRadius="1" HasShadow="false" Margin="10"
          BackgroundColor="White" BorderColor="Silver" Padding="0" >
          <ContentPresenter />
          </Frame>
          </ControlTemplate>
          </ContentView.ControlTemplate>
          </ContentView>


          As you can see there is a ContentPresenter that is what is going to be replaced with your content (one thing to take into account is that the ContentPresenter allows only one child so you wil have to put your StackLayout inside)



          <template:NewFrame>
          <StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
          <xaml:PtiXaml />
          <template:LineTemplate />
          <xaml:AtiXaml />
          <template:LineTemplate />
          <xaml:StiXaml />
          </StackLayout>
          </template:NewFrame>




          Another way would be to do a custom layout but it's more complicated and I wouldn't go that way to do that layout wrapper.






          share|improve this answer












          One way is the one that @Tom said and another one is using a Control template that is basically what you want I think.



          Even tough the docs said that




          Xamarin.Forms control templates provide the ability to easily theme and re-theme application pages at runtime. This article provides an introduction to control templates




          you can use the control template as a wrapper using it in a ContentView (I've done it and it works perfectly).



          In your case you'd have to do a ContentView and fill the ContentView.ControlTemplate with your layout of the wrapper:



          <ContentView
          xmlns="http://xamarin.com/schemas/2014/forms"
          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
          xmlns:... your namespaces
          x:Class="YourNamespace.NewFrame">
          <ContentView.ControlTemplate>
          <ControlTemplate>
          <Frame CornerRadius="1" HasShadow="false" Margin="10"
          BackgroundColor="White" BorderColor="Silver" Padding="0" >
          <ContentPresenter />
          </Frame>
          </ControlTemplate>
          </ContentView.ControlTemplate>
          </ContentView>


          As you can see there is a ContentPresenter that is what is going to be replaced with your content (one thing to take into account is that the ContentPresenter allows only one child so you wil have to put your StackLayout inside)



          <template:NewFrame>
          <StackLayout Orientation="Vertical" Spacing="0" Padding="0" >
          <xaml:PtiXaml />
          <template:LineTemplate />
          <xaml:AtiXaml />
          <template:LineTemplate />
          <xaml:StiXaml />
          </StackLayout>
          </template:NewFrame>




          Another way would be to do a custom layout but it's more complicated and I wouldn't go that way to do that layout wrapper.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 6 '18 at 13:07









          fmaccaroni

          2,3601824




          2,3601824

























              0














              C#:



              public class CustomFrame : Frame
              {
              public CustomEditor()
              {
              CornerRadius = 1;
              HasShadow = false;
              Margin = 10;
              BackgroundColor = Color.White;
              BorderColor = Color.Silver;
              Padding = 0;
              }
              }


              Usage:



              <template:CustomFrame>
              <StackLayout
              Orientation="Vertical"
              Spacing="0"
              Padding="0" >

              <xaml:PtiXaml />
              <template:LineTemplate />
              <xaml:AtiXaml />
              <template:LineTemplate />
              <xaml:StiXaml />

              </StackLayout>
              </template:CustomFrame>





              share|improve this answer


























                0














                C#:



                public class CustomFrame : Frame
                {
                public CustomEditor()
                {
                CornerRadius = 1;
                HasShadow = false;
                Margin = 10;
                BackgroundColor = Color.White;
                BorderColor = Color.Silver;
                Padding = 0;
                }
                }


                Usage:



                <template:CustomFrame>
                <StackLayout
                Orientation="Vertical"
                Spacing="0"
                Padding="0" >

                <xaml:PtiXaml />
                <template:LineTemplate />
                <xaml:AtiXaml />
                <template:LineTemplate />
                <xaml:StiXaml />

                </StackLayout>
                </template:CustomFrame>





                share|improve this answer
























                  0












                  0








                  0






                  C#:



                  public class CustomFrame : Frame
                  {
                  public CustomEditor()
                  {
                  CornerRadius = 1;
                  HasShadow = false;
                  Margin = 10;
                  BackgroundColor = Color.White;
                  BorderColor = Color.Silver;
                  Padding = 0;
                  }
                  }


                  Usage:



                  <template:CustomFrame>
                  <StackLayout
                  Orientation="Vertical"
                  Spacing="0"
                  Padding="0" >

                  <xaml:PtiXaml />
                  <template:LineTemplate />
                  <xaml:AtiXaml />
                  <template:LineTemplate />
                  <xaml:StiXaml />

                  </StackLayout>
                  </template:CustomFrame>





                  share|improve this answer












                  C#:



                  public class CustomFrame : Frame
                  {
                  public CustomEditor()
                  {
                  CornerRadius = 1;
                  HasShadow = false;
                  Margin = 10;
                  BackgroundColor = Color.White;
                  BorderColor = Color.Silver;
                  Padding = 0;
                  }
                  }


                  Usage:



                  <template:CustomFrame>
                  <StackLayout
                  Orientation="Vertical"
                  Spacing="0"
                  Padding="0" >

                  <xaml:PtiXaml />
                  <template:LineTemplate />
                  <xaml:AtiXaml />
                  <template:LineTemplate />
                  <xaml:StiXaml />

                  </StackLayout>
                  </template:CustomFrame>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 3 '18 at 12:42









                  Tom

                  1,055615




                  1,055615






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416901%2fhow-can-i-create-a-xaml-template-that-acts-as-a-wrapper-for-elements%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      Refactoring coordinates for Minecraft Pi buildings written in Python