How to translate this Padding with Device.OnPlatform? (iOS cases)












0















So Im working myself trough a xamarin.forms book right now and I came across this:



 Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);


Device.OnPlatform get´s a warning that it is obsolete.



I know that I could translate



Padding = Device.OnPlatform(new Thickness(0,20,0,0),
new Thickness(0),
new Thickness(0));


to



        switch (Device.RuntimePlatform)
{
case Device.iOS:
Padding = new Thickness(0, 20, 0, 0);
break;
};


But what exactly happens here and how do I translate this?



Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);









share|improve this question























  • You already know how to translate. That method was deprecated in 2016.

    – Bruno Caceiro
    Nov 26 '18 at 10:41











  • @BrunoCaceiro The thing is, I tried to rearrange. For example new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5); is not the same as new Thickness(Device.OnPlatform(20, 5, 5), 5, 5, 5); - So Device.OnPlatform(20, 5, 5) gives out a single value or what exactly is happening? I first assumed that it wont matter on what position Device.OnPlatform is but that is not the case.

    – axbeit
    Nov 26 '18 at 11:22











  • nvm.... Im bad.

    – axbeit
    Nov 26 '18 at 11:28
















0















So Im working myself trough a xamarin.forms book right now and I came across this:



 Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);


Device.OnPlatform get´s a warning that it is obsolete.



I know that I could translate



Padding = Device.OnPlatform(new Thickness(0,20,0,0),
new Thickness(0),
new Thickness(0));


to



        switch (Device.RuntimePlatform)
{
case Device.iOS:
Padding = new Thickness(0, 20, 0, 0);
break;
};


But what exactly happens here and how do I translate this?



Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);









share|improve this question























  • You already know how to translate. That method was deprecated in 2016.

    – Bruno Caceiro
    Nov 26 '18 at 10:41











  • @BrunoCaceiro The thing is, I tried to rearrange. For example new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5); is not the same as new Thickness(Device.OnPlatform(20, 5, 5), 5, 5, 5); - So Device.OnPlatform(20, 5, 5) gives out a single value or what exactly is happening? I first assumed that it wont matter on what position Device.OnPlatform is but that is not the case.

    – axbeit
    Nov 26 '18 at 11:22











  • nvm.... Im bad.

    – axbeit
    Nov 26 '18 at 11:28














0












0








0








So Im working myself trough a xamarin.forms book right now and I came across this:



 Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);


Device.OnPlatform get´s a warning that it is obsolete.



I know that I could translate



Padding = Device.OnPlatform(new Thickness(0,20,0,0),
new Thickness(0),
new Thickness(0));


to



        switch (Device.RuntimePlatform)
{
case Device.iOS:
Padding = new Thickness(0, 20, 0, 0);
break;
};


But what exactly happens here and how do I translate this?



Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);









share|improve this question














So Im working myself trough a xamarin.forms book right now and I came across this:



 Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);


Device.OnPlatform get´s a warning that it is obsolete.



I know that I could translate



Padding = Device.OnPlatform(new Thickness(0,20,0,0),
new Thickness(0),
new Thickness(0));


to



        switch (Device.RuntimePlatform)
{
case Device.iOS:
Padding = new Thickness(0, 20, 0, 0);
break;
};


But what exactly happens here and how do I translate this?



Padding = new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5);






c# ios xamarin xamarin.forms xamarin.ios






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 10:35









axbeitaxbeit

17111




17111













  • You already know how to translate. That method was deprecated in 2016.

    – Bruno Caceiro
    Nov 26 '18 at 10:41











  • @BrunoCaceiro The thing is, I tried to rearrange. For example new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5); is not the same as new Thickness(Device.OnPlatform(20, 5, 5), 5, 5, 5); - So Device.OnPlatform(20, 5, 5) gives out a single value or what exactly is happening? I first assumed that it wont matter on what position Device.OnPlatform is but that is not the case.

    – axbeit
    Nov 26 '18 at 11:22











  • nvm.... Im bad.

    – axbeit
    Nov 26 '18 at 11:28



















  • You already know how to translate. That method was deprecated in 2016.

    – Bruno Caceiro
    Nov 26 '18 at 10:41











  • @BrunoCaceiro The thing is, I tried to rearrange. For example new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5); is not the same as new Thickness(Device.OnPlatform(20, 5, 5), 5, 5, 5); - So Device.OnPlatform(20, 5, 5) gives out a single value or what exactly is happening? I first assumed that it wont matter on what position Device.OnPlatform is but that is not the case.

    – axbeit
    Nov 26 '18 at 11:22











  • nvm.... Im bad.

    – axbeit
    Nov 26 '18 at 11:28

















You already know how to translate. That method was deprecated in 2016.

– Bruno Caceiro
Nov 26 '18 at 10:41





You already know how to translate. That method was deprecated in 2016.

– Bruno Caceiro
Nov 26 '18 at 10:41













@BrunoCaceiro The thing is, I tried to rearrange. For example new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5); is not the same as new Thickness(Device.OnPlatform(20, 5, 5), 5, 5, 5); - So Device.OnPlatform(20, 5, 5) gives out a single value or what exactly is happening? I first assumed that it wont matter on what position Device.OnPlatform is but that is not the case.

– axbeit
Nov 26 '18 at 11:22





@BrunoCaceiro The thing is, I tried to rearrange. For example new Thickness(5, Device.OnPlatform(20, 5, 5), 5, 5); is not the same as new Thickness(Device.OnPlatform(20, 5, 5), 5, 5, 5); - So Device.OnPlatform(20, 5, 5) gives out a single value or what exactly is happening? I first assumed that it wont matter on what position Device.OnPlatform is but that is not the case.

– axbeit
Nov 26 '18 at 11:22













nvm.... Im bad.

– axbeit
Nov 26 '18 at 11:28





nvm.... Im bad.

– axbeit
Nov 26 '18 at 11:28












1 Answer
1






active

oldest

votes


















2














The new Thickness(5, 5, 5, 5); with 4 double parameters means that it will create a new padding (in this case) with 5 on the left, 5 on the top, 5 on the right and 5 on the bottom. So, from left to right, you just go clockwise and start from the left.



We see that the second parameter (so the top padding) will be different depending on the platform. From the top of my head, I am not sure what parameter is what platform, but I'm guessing the first one will be iOS. What happens now, is that the left will have a padding of 5 and the top padding will be different per platform. For iOS, it will be 20 and for Android and UWP (remember, just a guess) it will still be 5. Then the right and bottom padding didn't change, so they are still 5 as well.



If you want to do it strictly in code, it might translate to something like this:



double topPadding = 5;

switch (Device.RuntimePlatform)
{
case Device.iOS:
topPadding = 20;
break;
default:
topPadding = 5;
break;
};

Padding = new Thickness(5, topPadding, 5, 5);


Of course, you can add some different cases or change the values, totally up to you.



You can also do it with XAML. It could then look like this:



<YourControl Padding="{OnPlatform '5,5,5,5', iOS='5,20,5,5'}" />


YourControl is the control you want to apply this on. The first '5,5,5,5' value after OnPlatform is a default value for all platforms not specified. The iOS is specified and will thus use the value specified for it. Read more on the OnPlatform extension here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/markup-extensions/consuming#onplatform-markup-extension






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%2f53479248%2fhow-to-translate-this-padding-with-device-onplatform-ios-cases%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









    2














    The new Thickness(5, 5, 5, 5); with 4 double parameters means that it will create a new padding (in this case) with 5 on the left, 5 on the top, 5 on the right and 5 on the bottom. So, from left to right, you just go clockwise and start from the left.



    We see that the second parameter (so the top padding) will be different depending on the platform. From the top of my head, I am not sure what parameter is what platform, but I'm guessing the first one will be iOS. What happens now, is that the left will have a padding of 5 and the top padding will be different per platform. For iOS, it will be 20 and for Android and UWP (remember, just a guess) it will still be 5. Then the right and bottom padding didn't change, so they are still 5 as well.



    If you want to do it strictly in code, it might translate to something like this:



    double topPadding = 5;

    switch (Device.RuntimePlatform)
    {
    case Device.iOS:
    topPadding = 20;
    break;
    default:
    topPadding = 5;
    break;
    };

    Padding = new Thickness(5, topPadding, 5, 5);


    Of course, you can add some different cases or change the values, totally up to you.



    You can also do it with XAML. It could then look like this:



    <YourControl Padding="{OnPlatform '5,5,5,5', iOS='5,20,5,5'}" />


    YourControl is the control you want to apply this on. The first '5,5,5,5' value after OnPlatform is a default value for all platforms not specified. The iOS is specified and will thus use the value specified for it. Read more on the OnPlatform extension here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/markup-extensions/consuming#onplatform-markup-extension






    share|improve this answer






























      2














      The new Thickness(5, 5, 5, 5); with 4 double parameters means that it will create a new padding (in this case) with 5 on the left, 5 on the top, 5 on the right and 5 on the bottom. So, from left to right, you just go clockwise and start from the left.



      We see that the second parameter (so the top padding) will be different depending on the platform. From the top of my head, I am not sure what parameter is what platform, but I'm guessing the first one will be iOS. What happens now, is that the left will have a padding of 5 and the top padding will be different per platform. For iOS, it will be 20 and for Android and UWP (remember, just a guess) it will still be 5. Then the right and bottom padding didn't change, so they are still 5 as well.



      If you want to do it strictly in code, it might translate to something like this:



      double topPadding = 5;

      switch (Device.RuntimePlatform)
      {
      case Device.iOS:
      topPadding = 20;
      break;
      default:
      topPadding = 5;
      break;
      };

      Padding = new Thickness(5, topPadding, 5, 5);


      Of course, you can add some different cases or change the values, totally up to you.



      You can also do it with XAML. It could then look like this:



      <YourControl Padding="{OnPlatform '5,5,5,5', iOS='5,20,5,5'}" />


      YourControl is the control you want to apply this on. The first '5,5,5,5' value after OnPlatform is a default value for all platforms not specified. The iOS is specified and will thus use the value specified for it. Read more on the OnPlatform extension here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/markup-extensions/consuming#onplatform-markup-extension






      share|improve this answer




























        2












        2








        2







        The new Thickness(5, 5, 5, 5); with 4 double parameters means that it will create a new padding (in this case) with 5 on the left, 5 on the top, 5 on the right and 5 on the bottom. So, from left to right, you just go clockwise and start from the left.



        We see that the second parameter (so the top padding) will be different depending on the platform. From the top of my head, I am not sure what parameter is what platform, but I'm guessing the first one will be iOS. What happens now, is that the left will have a padding of 5 and the top padding will be different per platform. For iOS, it will be 20 and for Android and UWP (remember, just a guess) it will still be 5. Then the right and bottom padding didn't change, so they are still 5 as well.



        If you want to do it strictly in code, it might translate to something like this:



        double topPadding = 5;

        switch (Device.RuntimePlatform)
        {
        case Device.iOS:
        topPadding = 20;
        break;
        default:
        topPadding = 5;
        break;
        };

        Padding = new Thickness(5, topPadding, 5, 5);


        Of course, you can add some different cases or change the values, totally up to you.



        You can also do it with XAML. It could then look like this:



        <YourControl Padding="{OnPlatform '5,5,5,5', iOS='5,20,5,5'}" />


        YourControl is the control you want to apply this on. The first '5,5,5,5' value after OnPlatform is a default value for all platforms not specified. The iOS is specified and will thus use the value specified for it. Read more on the OnPlatform extension here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/markup-extensions/consuming#onplatform-markup-extension






        share|improve this answer















        The new Thickness(5, 5, 5, 5); with 4 double parameters means that it will create a new padding (in this case) with 5 on the left, 5 on the top, 5 on the right and 5 on the bottom. So, from left to right, you just go clockwise and start from the left.



        We see that the second parameter (so the top padding) will be different depending on the platform. From the top of my head, I am not sure what parameter is what platform, but I'm guessing the first one will be iOS. What happens now, is that the left will have a padding of 5 and the top padding will be different per platform. For iOS, it will be 20 and for Android and UWP (remember, just a guess) it will still be 5. Then the right and bottom padding didn't change, so they are still 5 as well.



        If you want to do it strictly in code, it might translate to something like this:



        double topPadding = 5;

        switch (Device.RuntimePlatform)
        {
        case Device.iOS:
        topPadding = 20;
        break;
        default:
        topPadding = 5;
        break;
        };

        Padding = new Thickness(5, topPadding, 5, 5);


        Of course, you can add some different cases or change the values, totally up to you.



        You can also do it with XAML. It could then look like this:



        <YourControl Padding="{OnPlatform '5,5,5,5', iOS='5,20,5,5'}" />


        YourControl is the control you want to apply this on. The first '5,5,5,5' value after OnPlatform is a default value for all platforms not specified. The iOS is specified and will thus use the value specified for it. Read more on the OnPlatform extension here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/markup-extensions/consuming#onplatform-markup-extension







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 26 '18 at 10:49

























        answered Nov 26 '18 at 10:41









        Gerald VersluisGerald Versluis

        17.6k43659




        17.6k43659
































            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%2f53479248%2fhow-to-translate-this-padding-with-device-onplatform-ios-cases%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

            Costa Masnaga

            Fotorealismo

            Sidney Franklin