user1122052
user1122052

Reputation: 341

Xamarin Forms Fixed Size for an image

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...

Upvotes: 3

Views: 6947

Answers (1)

Akash Amin
Akash Amin

Reputation: 2761

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>

Upvotes: 2

Related Questions