3. Xamarin中区分不同平台做适配OnPlatform

1. 第一种区分平台,在cs文件中区分, Device.OnPlatform 推荐

public UiRightViewModel()
{

    Device.OnPlatform(
        iOS: () =>
        {
            this.ThrottleViewWidth = 190 * AppSetting.Instance.HeightScale;
            this.ThrottleViewHeight = 200 * AppSetting.Instance.WidthScale;
        },
        Android: () => {
            this.ThrottleViewWidth = 190 * 3 * AppSetting.Instance.HeightScale;
            this.ThrottleViewHeight = 69 * 3 * AppSetting.Instance.WidthScale;
        }
    );
}

2. 第二种区分平台 ,xaml文件中, ContentPage.Resources




  
    
      ContentView

      
      

      
      
    
  

  
    
      
        
          
            
              
              
              
              
                
                
            
          
        
      
    
  
  

3. 第三种区分平台,xaml文件中

          
            
              
                                
                                    
                                        120
                                        60
                                    
                                
                                
                                
                                    
                                        120
                                        60
                                    
                                
                    
            
          

核心代码


                                    
                                        120
                                        60
                                    
                                

4. 第四种使用方式,简便写法

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

你可能感兴趣的:(3. Xamarin中区分不同平台做适配OnPlatform)