How to create new button in Xamarin












0















I'm really new in coding but I know a few things in C#.
I'm learning by myself just for the sake of it, for fun.
I've made some little programs in console and now I'm learning Xamarin.



For now, I've followed the xamarin tutorials (those with the "phoneword" app).



I'm now working on another app for android and I would like to know how to create a new button in code.



Example:
On the main page, the user presses a button that creates a new page where he can fill a form. After he finished, a new button appear on the main page that leads to the form previously filled.
So when the user open the app, he has to choose whether he opens a new form or accesses to the old form (because now there is a new button).



All I want to know is: how do I create this new button ?



I've look everywhere and can't find any working solution. I don't know if that matters, but all I can see is explanations for Xamarin.Forms and that's not what I'm using. I'm using Xamarin Native.



For example, I've tried :



Button b = new Button();
b.Content = "Test";
b.Click += OnClick;


But it's not working. VS returns various errors.
I understand that "Button()" needs parameters, but I don't know what to do.



Someone can give a little help, please ?



PS: I'm not a native speaker, so please don't mind some mistakes with English grammar.










share|improve this question

























  • "VS returns various errors" - it would be really helpful if you tell us what these errors are.

    – Jason
    Nov 21 '18 at 14:00






  • 1





    Xamarin Native can mean Xamarin.iOS, Xamarin.Android, Xamarin.Mac, maybe even some other flavors so you first need to say what you actually do.

    – Ivan Ičin
    Nov 21 '18 at 14:02






  • 1





    @DiegoRafaelSouza : didn't do it on purpose. Sorry.

    – Jojojojo
    Nov 21 '18 at 14:54






  • 1





    @IvanIčin as I wrote, it's for Android.

    – Jojojojo
    Nov 21 '18 at 14:55











  • @Jason Below you can check screens I uploaded. Thanks for helping !

    – Jojojojo
    Nov 21 '18 at 15:50
















0















I'm really new in coding but I know a few things in C#.
I'm learning by myself just for the sake of it, for fun.
I've made some little programs in console and now I'm learning Xamarin.



For now, I've followed the xamarin tutorials (those with the "phoneword" app).



I'm now working on another app for android and I would like to know how to create a new button in code.



Example:
On the main page, the user presses a button that creates a new page where he can fill a form. After he finished, a new button appear on the main page that leads to the form previously filled.
So when the user open the app, he has to choose whether he opens a new form or accesses to the old form (because now there is a new button).



All I want to know is: how do I create this new button ?



I've look everywhere and can't find any working solution. I don't know if that matters, but all I can see is explanations for Xamarin.Forms and that's not what I'm using. I'm using Xamarin Native.



For example, I've tried :



Button b = new Button();
b.Content = "Test";
b.Click += OnClick;


But it's not working. VS returns various errors.
I understand that "Button()" needs parameters, but I don't know what to do.



Someone can give a little help, please ?



PS: I'm not a native speaker, so please don't mind some mistakes with English grammar.










share|improve this question

























  • "VS returns various errors" - it would be really helpful if you tell us what these errors are.

    – Jason
    Nov 21 '18 at 14:00






  • 1





    Xamarin Native can mean Xamarin.iOS, Xamarin.Android, Xamarin.Mac, maybe even some other flavors so you first need to say what you actually do.

    – Ivan Ičin
    Nov 21 '18 at 14:02






  • 1





    @DiegoRafaelSouza : didn't do it on purpose. Sorry.

    – Jojojojo
    Nov 21 '18 at 14:54






  • 1





    @IvanIčin as I wrote, it's for Android.

    – Jojojojo
    Nov 21 '18 at 14:55











  • @Jason Below you can check screens I uploaded. Thanks for helping !

    – Jojojojo
    Nov 21 '18 at 15:50














0












0








0


0






I'm really new in coding but I know a few things in C#.
I'm learning by myself just for the sake of it, for fun.
I've made some little programs in console and now I'm learning Xamarin.



For now, I've followed the xamarin tutorials (those with the "phoneword" app).



I'm now working on another app for android and I would like to know how to create a new button in code.



Example:
On the main page, the user presses a button that creates a new page where he can fill a form. After he finished, a new button appear on the main page that leads to the form previously filled.
So when the user open the app, he has to choose whether he opens a new form or accesses to the old form (because now there is a new button).



All I want to know is: how do I create this new button ?



I've look everywhere and can't find any working solution. I don't know if that matters, but all I can see is explanations for Xamarin.Forms and that's not what I'm using. I'm using Xamarin Native.



For example, I've tried :



Button b = new Button();
b.Content = "Test";
b.Click += OnClick;


But it's not working. VS returns various errors.
I understand that "Button()" needs parameters, but I don't know what to do.



Someone can give a little help, please ?



PS: I'm not a native speaker, so please don't mind some mistakes with English grammar.










share|improve this question
















I'm really new in coding but I know a few things in C#.
I'm learning by myself just for the sake of it, for fun.
I've made some little programs in console and now I'm learning Xamarin.



For now, I've followed the xamarin tutorials (those with the "phoneword" app).



I'm now working on another app for android and I would like to know how to create a new button in code.



Example:
On the main page, the user presses a button that creates a new page where he can fill a form. After he finished, a new button appear on the main page that leads to the form previously filled.
So when the user open the app, he has to choose whether he opens a new form or accesses to the old form (because now there is a new button).



All I want to know is: how do I create this new button ?



I've look everywhere and can't find any working solution. I don't know if that matters, but all I can see is explanations for Xamarin.Forms and that's not what I'm using. I'm using Xamarin Native.



For example, I've tried :



Button b = new Button();
b.Content = "Test";
b.Click += OnClick;


But it's not working. VS returns various errors.
I understand that "Button()" needs parameters, but I don't know what to do.



Someone can give a little help, please ?



PS: I'm not a native speaker, so please don't mind some mistakes with English grammar.







c# xamarin button xamarin.android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 15:09









Diego Rafael Souza

3,33131242




3,33131242










asked Nov 21 '18 at 13:52









JojojojoJojojojo

31




31













  • "VS returns various errors" - it would be really helpful if you tell us what these errors are.

    – Jason
    Nov 21 '18 at 14:00






  • 1





    Xamarin Native can mean Xamarin.iOS, Xamarin.Android, Xamarin.Mac, maybe even some other flavors so you first need to say what you actually do.

    – Ivan Ičin
    Nov 21 '18 at 14:02






  • 1





    @DiegoRafaelSouza : didn't do it on purpose. Sorry.

    – Jojojojo
    Nov 21 '18 at 14:54






  • 1





    @IvanIčin as I wrote, it's for Android.

    – Jojojojo
    Nov 21 '18 at 14:55











  • @Jason Below you can check screens I uploaded. Thanks for helping !

    – Jojojojo
    Nov 21 '18 at 15:50



















  • "VS returns various errors" - it would be really helpful if you tell us what these errors are.

    – Jason
    Nov 21 '18 at 14:00






  • 1





    Xamarin Native can mean Xamarin.iOS, Xamarin.Android, Xamarin.Mac, maybe even some other flavors so you first need to say what you actually do.

    – Ivan Ičin
    Nov 21 '18 at 14:02






  • 1





    @DiegoRafaelSouza : didn't do it on purpose. Sorry.

    – Jojojojo
    Nov 21 '18 at 14:54






  • 1





    @IvanIčin as I wrote, it's for Android.

    – Jojojojo
    Nov 21 '18 at 14:55











  • @Jason Below you can check screens I uploaded. Thanks for helping !

    – Jojojojo
    Nov 21 '18 at 15:50

















"VS returns various errors" - it would be really helpful if you tell us what these errors are.

– Jason
Nov 21 '18 at 14:00





"VS returns various errors" - it would be really helpful if you tell us what these errors are.

– Jason
Nov 21 '18 at 14:00




1




1





Xamarin Native can mean Xamarin.iOS, Xamarin.Android, Xamarin.Mac, maybe even some other flavors so you first need to say what you actually do.

– Ivan Ičin
Nov 21 '18 at 14:02





Xamarin Native can mean Xamarin.iOS, Xamarin.Android, Xamarin.Mac, maybe even some other flavors so you first need to say what you actually do.

– Ivan Ičin
Nov 21 '18 at 14:02




1




1





@DiegoRafaelSouza : didn't do it on purpose. Sorry.

– Jojojojo
Nov 21 '18 at 14:54





@DiegoRafaelSouza : didn't do it on purpose. Sorry.

– Jojojojo
Nov 21 '18 at 14:54




1




1





@IvanIčin as I wrote, it's for Android.

– Jojojojo
Nov 21 '18 at 14:55





@IvanIčin as I wrote, it's for Android.

– Jojojojo
Nov 21 '18 at 14:55













@Jason Below you can check screens I uploaded. Thanks for helping !

– Jojojojo
Nov 21 '18 at 15:50





@Jason Below you can check screens I uploaded. Thanks for helping !

– Jojojojo
Nov 21 '18 at 15:50












3 Answers
3






active

oldest

votes


















0














First you need to create parameters of layout & than add those params to button like this



var params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent);    
Button b = new Button(this);
b.SetText("Test",TextView.BufferType.Normal);
b.Click=OnClick;
b.LayoutParameters = params;


Or add layout in your in axml like this



<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


Than in your activity get you Layout using Id & add button to it.



LinearLayout l_layout = (LinearLayout)FindViewById(Resource.Id.linear_layout);
l_layout.Orientation = Orientation.Horizontal;
Button b = new Button(this);
b.Click=OnClick;
b.SetText("Test",TextView.BufferType.Normal);
l_layout.AddView(b);





share|improve this answer
























  • Thanks for responding, I have some issues with both ways. Here you can check what VS returns : link and link . Thanks for helping !

    – Jojojojo
    Nov 21 '18 at 15:48











  • @Jojojojo The screenshots are hard to read (for instance I can't see your OnClick method), which it is why it is bad practise to use them. It is best to copy and paste your code and format it here according to the guidelines.

    – uprightbassfan78
    Nov 21 '18 at 15:59











  • @jojojo - For first part, do that inside 'OnCreate' method of your activity & your are not passing 'this' in button at right side as I provided code. Create 'OnClick' method too or you can comment that line.

    – CGPA6.4
    Nov 21 '18 at 17:00











  • @CGPA6.4 as a matter of fact, I noticed that I didn't and try it again, but I uploaded the wrong screen. Thanks

    – Jojojojo
    Nov 21 '18 at 20:09











  • So, I did what you said (comment the OnClick line) plus I rewrote the ID line (android:id="@+id/linear_layout"), and now it's working. Thanks a lot !

    – Jojojojo
    Nov 21 '18 at 21:13





















1














With this You can create the button You only need to add the size of the button and add it to some layout.



Xamarin.Forms



Button button = new Button();
button.Text = "Title";


Xamarin.Android



Button button = new Button(this); //if your using a fragment you have to use this.Activity
button.Text = "Title";


Xamarin.iOS



UIButton button = new UIButton();
button.SetTitle("Title", UIControlState.Normal);





share|improve this answer
























  • Thanks for responding. I tried but I don't know how to add a layout. So I tried @CGPA6.4 's way but got errors as you can see below.

    – Jojojojo
    Nov 21 '18 at 15:45











  • which platform are you using ?

    – Ricardo Romo
    Nov 21 '18 at 15:46



















0














Xamarin forms button example



var Tittlebutton= new Button
{
Text = "Title"
};





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%2f53413604%2fhow-to-create-new-button-in-xamarin%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    First you need to create parameters of layout & than add those params to button like this



    var params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent);    
    Button b = new Button(this);
    b.SetText("Test",TextView.BufferType.Normal);
    b.Click=OnClick;
    b.LayoutParameters = params;


    Or add layout in your in axml like this



    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    Than in your activity get you Layout using Id & add button to it.



    LinearLayout l_layout = (LinearLayout)FindViewById(Resource.Id.linear_layout);
    l_layout.Orientation = Orientation.Horizontal;
    Button b = new Button(this);
    b.Click=OnClick;
    b.SetText("Test",TextView.BufferType.Normal);
    l_layout.AddView(b);





    share|improve this answer
























    • Thanks for responding, I have some issues with both ways. Here you can check what VS returns : link and link . Thanks for helping !

      – Jojojojo
      Nov 21 '18 at 15:48











    • @Jojojojo The screenshots are hard to read (for instance I can't see your OnClick method), which it is why it is bad practise to use them. It is best to copy and paste your code and format it here according to the guidelines.

      – uprightbassfan78
      Nov 21 '18 at 15:59











    • @jojojo - For first part, do that inside 'OnCreate' method of your activity & your are not passing 'this' in button at right side as I provided code. Create 'OnClick' method too or you can comment that line.

      – CGPA6.4
      Nov 21 '18 at 17:00











    • @CGPA6.4 as a matter of fact, I noticed that I didn't and try it again, but I uploaded the wrong screen. Thanks

      – Jojojojo
      Nov 21 '18 at 20:09











    • So, I did what you said (comment the OnClick line) plus I rewrote the ID line (android:id="@+id/linear_layout"), and now it's working. Thanks a lot !

      – Jojojojo
      Nov 21 '18 at 21:13


















    0














    First you need to create parameters of layout & than add those params to button like this



    var params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent);    
    Button b = new Button(this);
    b.SetText("Test",TextView.BufferType.Normal);
    b.Click=OnClick;
    b.LayoutParameters = params;


    Or add layout in your in axml like this



    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    Than in your activity get you Layout using Id & add button to it.



    LinearLayout l_layout = (LinearLayout)FindViewById(Resource.Id.linear_layout);
    l_layout.Orientation = Orientation.Horizontal;
    Button b = new Button(this);
    b.Click=OnClick;
    b.SetText("Test",TextView.BufferType.Normal);
    l_layout.AddView(b);





    share|improve this answer
























    • Thanks for responding, I have some issues with both ways. Here you can check what VS returns : link and link . Thanks for helping !

      – Jojojojo
      Nov 21 '18 at 15:48











    • @Jojojojo The screenshots are hard to read (for instance I can't see your OnClick method), which it is why it is bad practise to use them. It is best to copy and paste your code and format it here according to the guidelines.

      – uprightbassfan78
      Nov 21 '18 at 15:59











    • @jojojo - For first part, do that inside 'OnCreate' method of your activity & your are not passing 'this' in button at right side as I provided code. Create 'OnClick' method too or you can comment that line.

      – CGPA6.4
      Nov 21 '18 at 17:00











    • @CGPA6.4 as a matter of fact, I noticed that I didn't and try it again, but I uploaded the wrong screen. Thanks

      – Jojojojo
      Nov 21 '18 at 20:09











    • So, I did what you said (comment the OnClick line) plus I rewrote the ID line (android:id="@+id/linear_layout"), and now it's working. Thanks a lot !

      – Jojojojo
      Nov 21 '18 at 21:13
















    0












    0








    0







    First you need to create parameters of layout & than add those params to button like this



    var params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent);    
    Button b = new Button(this);
    b.SetText("Test",TextView.BufferType.Normal);
    b.Click=OnClick;
    b.LayoutParameters = params;


    Or add layout in your in axml like this



    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    Than in your activity get you Layout using Id & add button to it.



    LinearLayout l_layout = (LinearLayout)FindViewById(Resource.Id.linear_layout);
    l_layout.Orientation = Orientation.Horizontal;
    Button b = new Button(this);
    b.Click=OnClick;
    b.SetText("Test",TextView.BufferType.Normal);
    l_layout.AddView(b);





    share|improve this answer













    First you need to create parameters of layout & than add those params to button like this



    var params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent);    
    Button b = new Button(this);
    b.SetText("Test",TextView.BufferType.Normal);
    b.Click=OnClick;
    b.LayoutParameters = params;


    Or add layout in your in axml like this



    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    Than in your activity get you Layout using Id & add button to it.



    LinearLayout l_layout = (LinearLayout)FindViewById(Resource.Id.linear_layout);
    l_layout.Orientation = Orientation.Horizontal;
    Button b = new Button(this);
    b.Click=OnClick;
    b.SetText("Test",TextView.BufferType.Normal);
    l_layout.AddView(b);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 14:28









    CGPA6.4CGPA6.4

    2,88831031




    2,88831031













    • Thanks for responding, I have some issues with both ways. Here you can check what VS returns : link and link . Thanks for helping !

      – Jojojojo
      Nov 21 '18 at 15:48











    • @Jojojojo The screenshots are hard to read (for instance I can't see your OnClick method), which it is why it is bad practise to use them. It is best to copy and paste your code and format it here according to the guidelines.

      – uprightbassfan78
      Nov 21 '18 at 15:59











    • @jojojo - For first part, do that inside 'OnCreate' method of your activity & your are not passing 'this' in button at right side as I provided code. Create 'OnClick' method too or you can comment that line.

      – CGPA6.4
      Nov 21 '18 at 17:00











    • @CGPA6.4 as a matter of fact, I noticed that I didn't and try it again, but I uploaded the wrong screen. Thanks

      – Jojojojo
      Nov 21 '18 at 20:09











    • So, I did what you said (comment the OnClick line) plus I rewrote the ID line (android:id="@+id/linear_layout"), and now it's working. Thanks a lot !

      – Jojojojo
      Nov 21 '18 at 21:13





















    • Thanks for responding, I have some issues with both ways. Here you can check what VS returns : link and link . Thanks for helping !

      – Jojojojo
      Nov 21 '18 at 15:48











    • @Jojojojo The screenshots are hard to read (for instance I can't see your OnClick method), which it is why it is bad practise to use them. It is best to copy and paste your code and format it here according to the guidelines.

      – uprightbassfan78
      Nov 21 '18 at 15:59











    • @jojojo - For first part, do that inside 'OnCreate' method of your activity & your are not passing 'this' in button at right side as I provided code. Create 'OnClick' method too or you can comment that line.

      – CGPA6.4
      Nov 21 '18 at 17:00











    • @CGPA6.4 as a matter of fact, I noticed that I didn't and try it again, but I uploaded the wrong screen. Thanks

      – Jojojojo
      Nov 21 '18 at 20:09











    • So, I did what you said (comment the OnClick line) plus I rewrote the ID line (android:id="@+id/linear_layout"), and now it's working. Thanks a lot !

      – Jojojojo
      Nov 21 '18 at 21:13



















    Thanks for responding, I have some issues with both ways. Here you can check what VS returns : link and link . Thanks for helping !

    – Jojojojo
    Nov 21 '18 at 15:48





    Thanks for responding, I have some issues with both ways. Here you can check what VS returns : link and link . Thanks for helping !

    – Jojojojo
    Nov 21 '18 at 15:48













    @Jojojojo The screenshots are hard to read (for instance I can't see your OnClick method), which it is why it is bad practise to use them. It is best to copy and paste your code and format it here according to the guidelines.

    – uprightbassfan78
    Nov 21 '18 at 15:59





    @Jojojojo The screenshots are hard to read (for instance I can't see your OnClick method), which it is why it is bad practise to use them. It is best to copy and paste your code and format it here according to the guidelines.

    – uprightbassfan78
    Nov 21 '18 at 15:59













    @jojojo - For first part, do that inside 'OnCreate' method of your activity & your are not passing 'this' in button at right side as I provided code. Create 'OnClick' method too or you can comment that line.

    – CGPA6.4
    Nov 21 '18 at 17:00





    @jojojo - For first part, do that inside 'OnCreate' method of your activity & your are not passing 'this' in button at right side as I provided code. Create 'OnClick' method too or you can comment that line.

    – CGPA6.4
    Nov 21 '18 at 17:00













    @CGPA6.4 as a matter of fact, I noticed that I didn't and try it again, but I uploaded the wrong screen. Thanks

    – Jojojojo
    Nov 21 '18 at 20:09





    @CGPA6.4 as a matter of fact, I noticed that I didn't and try it again, but I uploaded the wrong screen. Thanks

    – Jojojojo
    Nov 21 '18 at 20:09













    So, I did what you said (comment the OnClick line) plus I rewrote the ID line (android:id="@+id/linear_layout"), and now it's working. Thanks a lot !

    – Jojojojo
    Nov 21 '18 at 21:13







    So, I did what you said (comment the OnClick line) plus I rewrote the ID line (android:id="@+id/linear_layout"), and now it's working. Thanks a lot !

    – Jojojojo
    Nov 21 '18 at 21:13















    1














    With this You can create the button You only need to add the size of the button and add it to some layout.



    Xamarin.Forms



    Button button = new Button();
    button.Text = "Title";


    Xamarin.Android



    Button button = new Button(this); //if your using a fragment you have to use this.Activity
    button.Text = "Title";


    Xamarin.iOS



    UIButton button = new UIButton();
    button.SetTitle("Title", UIControlState.Normal);





    share|improve this answer
























    • Thanks for responding. I tried but I don't know how to add a layout. So I tried @CGPA6.4 's way but got errors as you can see below.

      – Jojojojo
      Nov 21 '18 at 15:45











    • which platform are you using ?

      – Ricardo Romo
      Nov 21 '18 at 15:46
















    1














    With this You can create the button You only need to add the size of the button and add it to some layout.



    Xamarin.Forms



    Button button = new Button();
    button.Text = "Title";


    Xamarin.Android



    Button button = new Button(this); //if your using a fragment you have to use this.Activity
    button.Text = "Title";


    Xamarin.iOS



    UIButton button = new UIButton();
    button.SetTitle("Title", UIControlState.Normal);





    share|improve this answer
























    • Thanks for responding. I tried but I don't know how to add a layout. So I tried @CGPA6.4 's way but got errors as you can see below.

      – Jojojojo
      Nov 21 '18 at 15:45











    • which platform are you using ?

      – Ricardo Romo
      Nov 21 '18 at 15:46














    1












    1








    1







    With this You can create the button You only need to add the size of the button and add it to some layout.



    Xamarin.Forms



    Button button = new Button();
    button.Text = "Title";


    Xamarin.Android



    Button button = new Button(this); //if your using a fragment you have to use this.Activity
    button.Text = "Title";


    Xamarin.iOS



    UIButton button = new UIButton();
    button.SetTitle("Title", UIControlState.Normal);





    share|improve this answer













    With this You can create the button You only need to add the size of the button and add it to some layout.



    Xamarin.Forms



    Button button = new Button();
    button.Text = "Title";


    Xamarin.Android



    Button button = new Button(this); //if your using a fragment you have to use this.Activity
    button.Text = "Title";


    Xamarin.iOS



    UIButton button = new UIButton();
    button.SetTitle("Title", UIControlState.Normal);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 14:18









    Ricardo RomoRicardo Romo

    809820




    809820













    • Thanks for responding. I tried but I don't know how to add a layout. So I tried @CGPA6.4 's way but got errors as you can see below.

      – Jojojojo
      Nov 21 '18 at 15:45











    • which platform are you using ?

      – Ricardo Romo
      Nov 21 '18 at 15:46



















    • Thanks for responding. I tried but I don't know how to add a layout. So I tried @CGPA6.4 's way but got errors as you can see below.

      – Jojojojo
      Nov 21 '18 at 15:45











    • which platform are you using ?

      – Ricardo Romo
      Nov 21 '18 at 15:46

















    Thanks for responding. I tried but I don't know how to add a layout. So I tried @CGPA6.4 's way but got errors as you can see below.

    – Jojojojo
    Nov 21 '18 at 15:45





    Thanks for responding. I tried but I don't know how to add a layout. So I tried @CGPA6.4 's way but got errors as you can see below.

    – Jojojojo
    Nov 21 '18 at 15:45













    which platform are you using ?

    – Ricardo Romo
    Nov 21 '18 at 15:46





    which platform are you using ?

    – Ricardo Romo
    Nov 21 '18 at 15:46











    0














    Xamarin forms button example



    var Tittlebutton= new Button
    {
    Text = "Title"
    };





    share|improve this answer




























      0














      Xamarin forms button example



      var Tittlebutton= new Button
      {
      Text = "Title"
      };





      share|improve this answer


























        0












        0








        0







        Xamarin forms button example



        var Tittlebutton= new Button
        {
        Text = "Title"
        };





        share|improve this answer













        Xamarin forms button example



        var Tittlebutton= new Button
        {
        Text = "Title"
        };






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 3 '18 at 9:40









        Chetan RawatChetan Rawat

        83




        83






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413604%2fhow-to-create-new-button-in-xamarin%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







            這個網誌中的熱門文章

            Hercules Kyvelos

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud