Search code examples
windows-phonecross-platformxamarin.forms

Image scaling on Windows Phone with Xamarin Forms


I am working on a Xamarin.Forms project and am having issues with the scaling of images with Windows Phone. Windows and Android

I'm using a Grid to display all of the icons, here is the code I used for 1 image button.

<Button Image="cam.png"
        VerticalOptions="Center"
        Grid.Row="0" Grid.Column="0"
        BorderColor="Transparent"
        BackgroundColor="Transparent"
        Clicked="OnTrafficClicked"/>

I've found a couple similar posts about this, but I don't understand how I would implement scaling on platform when there are multiple images.

I tried this, but am unable to run the program

<Image.Scale>
  <OnPlatform x:TypeArguments="Scale"
              WinPhone="1.5" />
</Image.Scale>

https://forums.xamarin.com/discussion/19525/image-source-with-onplatform-in-xaml


Solution

  • I was able to figure it out, in case anyone has this same issue this is what I did:

    <ContentPage.Resources>
        <ResourceDictionary>
          <OnPlatform x:Key="stdScaling" x:TypeArguments="x:Double"
          iOS="1.0"
          Android="1.0"
          WinPhone="2.5" />
        </ResourceDictionary>
    </ContentPage.Resources>
    

    then for the button, I put

    Scale= "{StaticResource stdScaling}"