How can I create a new Xamarin Element based on a Frame with a StackLayout inside of it?











up vote
0
down vote

favorite












I have a Frame with a StackLayout inside of it:



<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>


Can I create a new object called NewFrame that is the same as the Frame with the StackLayout inside?



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


or



<template:NewFrame>
<xaml:ABCXaml />
</template:NewFrame>


or



<template:NewFrame>
<Label Text="X" />
</template:NewFrame>


It was suggested I use a Custom View but I have looked and can not find an example of this where it contains other elements inside.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a Frame with a StackLayout inside of it:



    <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>


    Can I create a new object called NewFrame that is the same as the Frame with the StackLayout inside?



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


    or



    <template:NewFrame>
    <xaml:ABCXaml />
    </template:NewFrame>


    or



    <template:NewFrame>
    <Label Text="X" />
    </template:NewFrame>


    It was suggested I use a Custom View but I have looked and can not find an example of this where it contains other elements inside.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a Frame with a StackLayout inside of it:



      <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>


      Can I create a new object called NewFrame that is the same as the Frame with the StackLayout inside?



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


      or



      <template:NewFrame>
      <xaml:ABCXaml />
      </template:NewFrame>


      or



      <template:NewFrame>
      <Label Text="X" />
      </template:NewFrame>


      It was suggested I use a Custom View but I have looked and can not find an example of this where it contains other elements inside.










      share|improve this question













      I have a Frame with a StackLayout inside of it:



      <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>


      Can I create a new object called NewFrame that is the same as the Frame with the StackLayout inside?



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


      or



      <template:NewFrame>
      <xaml:ABCXaml />
      </template:NewFrame>


      or



      <template:NewFrame>
      <Label Text="X" />
      </template:NewFrame>


      It was suggested I use a Custom View but I have looked and can not find an example of this where it contains other elements inside.







      xamarin xamarin.forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 0:10









      Alan2

      1,30854131250




      1,30854131250
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Right-Click at the desired position in your Shared Project (or PCL) in your Solution Explorer (I would recommend adding a folder named "Views" or "CustomViews" and creating the item inside that folder), select "Add new item" and choose "Content View" (without (C#) behind it. The filename should be something like "View1.xaml", you can change that due to your liking, however the important thing is that the xaml extension is there.



          This will create a new ContentView with a xaml and xaml.cs file.
          Inside the xaml file you can declare your xaml code posted above and write any code necessary into the xaml.cs file.



          Now you can add a namespace declaration to the page you want to put your view into:



          <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
          ...
          xmlns:customs="clr-namespace:YourNamespace.Views;assembly=YourNamespace"


          and declare the element in that Page's or any layout's content:



          <customs:CustomViewName ... />


          If you want to be able to control the element's behaviour you can add BindableProperties in the codebehind.



          For more in-depth information on that, you might want to take a look into this article: https://visualstudiomagazine.com/articles/2017/10/01/add-custom-controls.aspx






          share|improve this answer





















          • The problem for me is that it's just a Frame and there are different XAML codes inside the frame. Not just one same set of XAML. Do you know how I can deal with that?
            – Alan2
            Nov 22 at 11:23










          • No, I don't see any good way to do that. You could create multiple classes, each for every variation
            – Markus Michel
            Nov 22 at 11:25











          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',
          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%2f53422182%2fhow-can-i-create-a-new-xamarin-element-based-on-a-frame-with-a-stacklayout-insid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          Right-Click at the desired position in your Shared Project (or PCL) in your Solution Explorer (I would recommend adding a folder named "Views" or "CustomViews" and creating the item inside that folder), select "Add new item" and choose "Content View" (without (C#) behind it. The filename should be something like "View1.xaml", you can change that due to your liking, however the important thing is that the xaml extension is there.



          This will create a new ContentView with a xaml and xaml.cs file.
          Inside the xaml file you can declare your xaml code posted above and write any code necessary into the xaml.cs file.



          Now you can add a namespace declaration to the page you want to put your view into:



          <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
          ...
          xmlns:customs="clr-namespace:YourNamespace.Views;assembly=YourNamespace"


          and declare the element in that Page's or any layout's content:



          <customs:CustomViewName ... />


          If you want to be able to control the element's behaviour you can add BindableProperties in the codebehind.



          For more in-depth information on that, you might want to take a look into this article: https://visualstudiomagazine.com/articles/2017/10/01/add-custom-controls.aspx






          share|improve this answer





















          • The problem for me is that it's just a Frame and there are different XAML codes inside the frame. Not just one same set of XAML. Do you know how I can deal with that?
            – Alan2
            Nov 22 at 11:23










          • No, I don't see any good way to do that. You could create multiple classes, each for every variation
            – Markus Michel
            Nov 22 at 11:25















          up vote
          0
          down vote













          Right-Click at the desired position in your Shared Project (or PCL) in your Solution Explorer (I would recommend adding a folder named "Views" or "CustomViews" and creating the item inside that folder), select "Add new item" and choose "Content View" (without (C#) behind it. The filename should be something like "View1.xaml", you can change that due to your liking, however the important thing is that the xaml extension is there.



          This will create a new ContentView with a xaml and xaml.cs file.
          Inside the xaml file you can declare your xaml code posted above and write any code necessary into the xaml.cs file.



          Now you can add a namespace declaration to the page you want to put your view into:



          <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
          ...
          xmlns:customs="clr-namespace:YourNamespace.Views;assembly=YourNamespace"


          and declare the element in that Page's or any layout's content:



          <customs:CustomViewName ... />


          If you want to be able to control the element's behaviour you can add BindableProperties in the codebehind.



          For more in-depth information on that, you might want to take a look into this article: https://visualstudiomagazine.com/articles/2017/10/01/add-custom-controls.aspx






          share|improve this answer





















          • The problem for me is that it's just a Frame and there are different XAML codes inside the frame. Not just one same set of XAML. Do you know how I can deal with that?
            – Alan2
            Nov 22 at 11:23










          • No, I don't see any good way to do that. You could create multiple classes, each for every variation
            – Markus Michel
            Nov 22 at 11:25













          up vote
          0
          down vote










          up vote
          0
          down vote









          Right-Click at the desired position in your Shared Project (or PCL) in your Solution Explorer (I would recommend adding a folder named "Views" or "CustomViews" and creating the item inside that folder), select "Add new item" and choose "Content View" (without (C#) behind it. The filename should be something like "View1.xaml", you can change that due to your liking, however the important thing is that the xaml extension is there.



          This will create a new ContentView with a xaml and xaml.cs file.
          Inside the xaml file you can declare your xaml code posted above and write any code necessary into the xaml.cs file.



          Now you can add a namespace declaration to the page you want to put your view into:



          <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
          ...
          xmlns:customs="clr-namespace:YourNamespace.Views;assembly=YourNamespace"


          and declare the element in that Page's or any layout's content:



          <customs:CustomViewName ... />


          If you want to be able to control the element's behaviour you can add BindableProperties in the codebehind.



          For more in-depth information on that, you might want to take a look into this article: https://visualstudiomagazine.com/articles/2017/10/01/add-custom-controls.aspx






          share|improve this answer












          Right-Click at the desired position in your Shared Project (or PCL) in your Solution Explorer (I would recommend adding a folder named "Views" or "CustomViews" and creating the item inside that folder), select "Add new item" and choose "Content View" (without (C#) behind it. The filename should be something like "View1.xaml", you can change that due to your liking, however the important thing is that the xaml extension is there.



          This will create a new ContentView with a xaml and xaml.cs file.
          Inside the xaml file you can declare your xaml code posted above and write any code necessary into the xaml.cs file.



          Now you can add a namespace declaration to the page you want to put your view into:



          <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
          ...
          xmlns:customs="clr-namespace:YourNamespace.Views;assembly=YourNamespace"


          and declare the element in that Page's or any layout's content:



          <customs:CustomViewName ... />


          If you want to be able to control the element's behaviour you can add BindableProperties in the codebehind.



          For more in-depth information on that, you might want to take a look into this article: https://visualstudiomagazine.com/articles/2017/10/01/add-custom-controls.aspx







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 11:05









          Markus Michel

          1,402214




          1,402214












          • The problem for me is that it's just a Frame and there are different XAML codes inside the frame. Not just one same set of XAML. Do you know how I can deal with that?
            – Alan2
            Nov 22 at 11:23










          • No, I don't see any good way to do that. You could create multiple classes, each for every variation
            – Markus Michel
            Nov 22 at 11:25


















          • The problem for me is that it's just a Frame and there are different XAML codes inside the frame. Not just one same set of XAML. Do you know how I can deal with that?
            – Alan2
            Nov 22 at 11:23










          • No, I don't see any good way to do that. You could create multiple classes, each for every variation
            – Markus Michel
            Nov 22 at 11:25
















          The problem for me is that it's just a Frame and there are different XAML codes inside the frame. Not just one same set of XAML. Do you know how I can deal with that?
          – Alan2
          Nov 22 at 11:23




          The problem for me is that it's just a Frame and there are different XAML codes inside the frame. Not just one same set of XAML. Do you know how I can deal with that?
          – Alan2
          Nov 22 at 11:23












          No, I don't see any good way to do that. You could create multiple classes, each for every variation
          – Markus Michel
          Nov 22 at 11:25




          No, I don't see any good way to do that. You could create multiple classes, each for every variation
          – Markus Michel
          Nov 22 at 11:25


















          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%2f53422182%2fhow-can-i-create-a-new-xamarin-element-based-on-a-frame-with-a-stacklayout-insid%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

          Lallio

          Unable to find Lightning Node

          Futebolista