3
votes

I'm trying to set the height and width of my image and have it a fixed size however if I shrink the container (frame, stackpanel, grid, etc...) the image shrinks along with it. However I would have assumed setting the height and width (WidthRequest, HeightRequest, MinimumHeightRequest, MinimumWidthRequest) would have forced the image to remain the set size... however it doesn't/

What can I do...

1
Have you test with Aspect property of the Image there are 3 different kinds of Aspects: AspectFill, AspectFit and Fill: more in detail here: developer.xamarin.com/api/type/Xamarin.Forms.AspectMario Galván

1 Answers

2
votes

Try this; This will set the width and height of the image with the platform specific dimensions i.e. it will use dp for android and points for iOS.

<Image IsVisible="true">
          <Image.HeightRequest>
            <OnIdiom x:TypeArguments="x:Double">
              <OnIdiom.Phone>
                <OnPlatform x:TypeArguments="x:Double" iOS="72" Android="100" WinPhone="10" />
              </OnIdiom.Phone>
              <OnIdiom.Tablet>
                <OnPlatform x:TypeArguments="x:Double" iOS="212" Android="140" WinPhone="10" />
              </OnIdiom.Tablet>
            </OnIdiom>
          </Image.HeightRequest>
          <Image.WidthRequest>
            <OnIdiom x:TypeArguments="x:Double">
              <OnIdiom.Phone>
                <OnPlatform x:TypeArguments="x:Double" iOS="125" Android="150" WinPhone="10" />
              </OnIdiom.Phone>
              <OnIdiom.Tablet>
                <OnPlatform x:TypeArguments="x:Double" iOS="265" Android="190" WinPhone="10" />
              </OnIdiom.Tablet>
            </OnIdiom>
          </Image.WidthRequest>
          <Image.Source>
            <OnPlatform x:TypeArguments="ImageSource">
              <OnPlatform.iOS>
                <FileImageSource File="logo.png" />
              </OnPlatform.iOS>
              <OnPlatform.Android>
                <FileImageSource File="logo.png" />
              </OnPlatform.Android>
              <OnPlatform.WinPhone>
                <FileImageSource File="logo.png" />
              </OnPlatform.WinPhone>
            </OnPlatform>
          </Image.Source>
        </Image>