Different Color For different application xamarin

jokertn 61 Reputation points
2021-05-29T15:59:49.447+00:00

i created a project named :'Proj1' and i created Proje1.Client1.Android , Proje1.Client2.Android , Proje1.Client1.iOS and Proj1.Client2.iOS
i created a AppConfiguration: in the projet Proj1

public class AppConfiguration
    {

        public static class Colors
        {
            public static Color Client1= Color.Black;
            public static Color Client2= Color.White;
        }

        public static class Images
        {
            public static string Client1= "logo1.png";
            public static string Client2= "logo2.png";
        }
 }

and i created Controls Class :

public class CustomButton : Button
    {
        public CustomButton()
        { 
BackgroundColor = AppConfig.Colors.Client1;
}    
    }

and short code from xaml code:

<StackLayout>
<Button:CustomButton />
</StackLayout>

i want to know if there is a solution for configure color and images for each application (Client1,Client2)

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,380 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,971 Reputation points
    2021-05-31T01:49:32.097+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    To specify a background color for the view, try using the data binding.

       <StackLayout>  
           <Button:CustomButton BackgroundColor="{Binding TheBackground}"/>  
       </StackLayout>  
    

    Then detect the project name to set different values for the binding parameter.

       var appName = AppInfo.Name;  
       switch (appName)  
       {  
           case "Proje1.Client1.Android":  
               TheBackground = Color.Red;  
               break;  
           case "Proje1.Client2.Android":  
               ...  
                           break;  
           case "Proje1.Client1.iOS":  
               ...  
                           break;  
           case "Proj1.Client2.iOS":  
               ...  
                           break;  
           default:  
               TheBackground = Color.Default;  
               break;  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.