Xamarin forms set max height image












0














I've been searching for this but can't find anything.



I wanna to set a max height to an image. It could be inside some other element or not.



I don't wanna that image to be with a static size.



I apreciate any help










share|improve this question






















  • There is no universal answer. Xamarin layout is complex and it isn't easy way to set anything to be 100% in the fixed size (in your case maximum size) without knowing the context. So you must show your current code first.
    – Ivan Ičin
    Nov 19 '18 at 21:26


















0














I've been searching for this but can't find anything.



I wanna to set a max height to an image. It could be inside some other element or not.



I don't wanna that image to be with a static size.



I apreciate any help










share|improve this question






















  • There is no universal answer. Xamarin layout is complex and it isn't easy way to set anything to be 100% in the fixed size (in your case maximum size) without knowing the context. So you must show your current code first.
    – Ivan Ičin
    Nov 19 '18 at 21:26
















0












0








0







I've been searching for this but can't find anything.



I wanna to set a max height to an image. It could be inside some other element or not.



I don't wanna that image to be with a static size.



I apreciate any help










share|improve this question













I've been searching for this but can't find anything.



I wanna to set a max height to an image. It could be inside some other element or not.



I don't wanna that image to be with a static size.



I apreciate any help







xamarin xamarin.forms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 16:05









micael cunha

147114




147114












  • There is no universal answer. Xamarin layout is complex and it isn't easy way to set anything to be 100% in the fixed size (in your case maximum size) without knowing the context. So you must show your current code first.
    – Ivan Ičin
    Nov 19 '18 at 21:26




















  • There is no universal answer. Xamarin layout is complex and it isn't easy way to set anything to be 100% in the fixed size (in your case maximum size) without knowing the context. So you must show your current code first.
    – Ivan Ičin
    Nov 19 '18 at 21:26


















There is no universal answer. Xamarin layout is complex and it isn't easy way to set anything to be 100% in the fixed size (in your case maximum size) without knowing the context. So you must show your current code first.
– Ivan Ičin
Nov 19 '18 at 21:26






There is no universal answer. Xamarin layout is complex and it isn't easy way to set anything to be 100% in the fixed size (in your case maximum size) without knowing the context. So you must show your current code first.
– Ivan Ičin
Nov 19 '18 at 21:26














2 Answers
2






active

oldest

votes


















2














There is no max height property in Xamarin.Forms, and it is not supported with the CSS styling either. There is already an enhancement request to add a max height property: https://www.google.com/search?q=Xamarin.+Forms+maximum+height&oq=Xamarin.+Forms+maximum+height&aqs=chrome..69i57j0.6714j0j7&sourceid=chrome&ie=UTF-8



However, you could monitor the SizeChanged event for the Image and check the height and reset it as necessary, e.g.:



XAML:



<Image x:Name="image" Source="imagename.png" />


C# code behind:



public MainPage()
{
InitializeComponent();

image.SizeChanged += (sender, e) => {
if (image.Height > 50)
image.HeightRequest = 50;
};
}





share|improve this answer





















  • In many cases (e.g. if Image VerticalOptions is Fill) this won't work, and actually I would expect that this won't work in his app, though it might work in some situations yes.
    – Ivan Ičin
    Nov 19 '18 at 21:25










  • Yeah, I thought about that after I posted it. Another option might be a custom renderer, but setting the height in a custom renderer for the Image won't update the layout for the surrounding elements based on the new image height.
    – jgoldberger - MSFT
    Nov 19 '18 at 22:13










  • That works for now. Thanks @jgoldberger
    – micael cunha
    Nov 22 '18 at 14:42





















0














You can play with the VerticalOptions and Aspect properties of the Image object to get the desired result.



Example :



var img = new Image() { 
Source = "picture.png",
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Aspect = Aspect.AspectFill
};





share|improve this answer





















  • That doesn't allow me to set max height
    – micael cunha
    Nov 19 '18 at 17:10










  • @micaelcunha, can you provide some code in your question?
    – chaosifier
    Nov 19 '18 at 17:11










  • I just have a image with AspectFit, I just wanna to set it with max height so that never be big than x.
    – micael cunha
    Nov 19 '18 at 17:20










  • Without looking at your code or xaml, it's going to be hard to help you.
    – chaosifier
    Nov 19 '18 at 17:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378538%2fxamarin-forms-set-max-height-image%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














There is no max height property in Xamarin.Forms, and it is not supported with the CSS styling either. There is already an enhancement request to add a max height property: https://www.google.com/search?q=Xamarin.+Forms+maximum+height&oq=Xamarin.+Forms+maximum+height&aqs=chrome..69i57j0.6714j0j7&sourceid=chrome&ie=UTF-8



However, you could monitor the SizeChanged event for the Image and check the height and reset it as necessary, e.g.:



XAML:



<Image x:Name="image" Source="imagename.png" />


C# code behind:



public MainPage()
{
InitializeComponent();

image.SizeChanged += (sender, e) => {
if (image.Height > 50)
image.HeightRequest = 50;
};
}





share|improve this answer





















  • In many cases (e.g. if Image VerticalOptions is Fill) this won't work, and actually I would expect that this won't work in his app, though it might work in some situations yes.
    – Ivan Ičin
    Nov 19 '18 at 21:25










  • Yeah, I thought about that after I posted it. Another option might be a custom renderer, but setting the height in a custom renderer for the Image won't update the layout for the surrounding elements based on the new image height.
    – jgoldberger - MSFT
    Nov 19 '18 at 22:13










  • That works for now. Thanks @jgoldberger
    – micael cunha
    Nov 22 '18 at 14:42


















2














There is no max height property in Xamarin.Forms, and it is not supported with the CSS styling either. There is already an enhancement request to add a max height property: https://www.google.com/search?q=Xamarin.+Forms+maximum+height&oq=Xamarin.+Forms+maximum+height&aqs=chrome..69i57j0.6714j0j7&sourceid=chrome&ie=UTF-8



However, you could monitor the SizeChanged event for the Image and check the height and reset it as necessary, e.g.:



XAML:



<Image x:Name="image" Source="imagename.png" />


C# code behind:



public MainPage()
{
InitializeComponent();

image.SizeChanged += (sender, e) => {
if (image.Height > 50)
image.HeightRequest = 50;
};
}





share|improve this answer





















  • In many cases (e.g. if Image VerticalOptions is Fill) this won't work, and actually I would expect that this won't work in his app, though it might work in some situations yes.
    – Ivan Ičin
    Nov 19 '18 at 21:25










  • Yeah, I thought about that after I posted it. Another option might be a custom renderer, but setting the height in a custom renderer for the Image won't update the layout for the surrounding elements based on the new image height.
    – jgoldberger - MSFT
    Nov 19 '18 at 22:13










  • That works for now. Thanks @jgoldberger
    – micael cunha
    Nov 22 '18 at 14:42
















2












2








2






There is no max height property in Xamarin.Forms, and it is not supported with the CSS styling either. There is already an enhancement request to add a max height property: https://www.google.com/search?q=Xamarin.+Forms+maximum+height&oq=Xamarin.+Forms+maximum+height&aqs=chrome..69i57j0.6714j0j7&sourceid=chrome&ie=UTF-8



However, you could monitor the SizeChanged event for the Image and check the height and reset it as necessary, e.g.:



XAML:



<Image x:Name="image" Source="imagename.png" />


C# code behind:



public MainPage()
{
InitializeComponent();

image.SizeChanged += (sender, e) => {
if (image.Height > 50)
image.HeightRequest = 50;
};
}





share|improve this answer












There is no max height property in Xamarin.Forms, and it is not supported with the CSS styling either. There is already an enhancement request to add a max height property: https://www.google.com/search?q=Xamarin.+Forms+maximum+height&oq=Xamarin.+Forms+maximum+height&aqs=chrome..69i57j0.6714j0j7&sourceid=chrome&ie=UTF-8



However, you could monitor the SizeChanged event for the Image and check the height and reset it as necessary, e.g.:



XAML:



<Image x:Name="image" Source="imagename.png" />


C# code behind:



public MainPage()
{
InitializeComponent();

image.SizeChanged += (sender, e) => {
if (image.Height > 50)
image.HeightRequest = 50;
};
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 20:27









jgoldberger - MSFT

3,4081827




3,4081827












  • In many cases (e.g. if Image VerticalOptions is Fill) this won't work, and actually I would expect that this won't work in his app, though it might work in some situations yes.
    – Ivan Ičin
    Nov 19 '18 at 21:25










  • Yeah, I thought about that after I posted it. Another option might be a custom renderer, but setting the height in a custom renderer for the Image won't update the layout for the surrounding elements based on the new image height.
    – jgoldberger - MSFT
    Nov 19 '18 at 22:13










  • That works for now. Thanks @jgoldberger
    – micael cunha
    Nov 22 '18 at 14:42




















  • In many cases (e.g. if Image VerticalOptions is Fill) this won't work, and actually I would expect that this won't work in his app, though it might work in some situations yes.
    – Ivan Ičin
    Nov 19 '18 at 21:25










  • Yeah, I thought about that after I posted it. Another option might be a custom renderer, but setting the height in a custom renderer for the Image won't update the layout for the surrounding elements based on the new image height.
    – jgoldberger - MSFT
    Nov 19 '18 at 22:13










  • That works for now. Thanks @jgoldberger
    – micael cunha
    Nov 22 '18 at 14:42


















In many cases (e.g. if Image VerticalOptions is Fill) this won't work, and actually I would expect that this won't work in his app, though it might work in some situations yes.
– Ivan Ičin
Nov 19 '18 at 21:25




In many cases (e.g. if Image VerticalOptions is Fill) this won't work, and actually I would expect that this won't work in his app, though it might work in some situations yes.
– Ivan Ičin
Nov 19 '18 at 21:25












Yeah, I thought about that after I posted it. Another option might be a custom renderer, but setting the height in a custom renderer for the Image won't update the layout for the surrounding elements based on the new image height.
– jgoldberger - MSFT
Nov 19 '18 at 22:13




Yeah, I thought about that after I posted it. Another option might be a custom renderer, but setting the height in a custom renderer for the Image won't update the layout for the surrounding elements based on the new image height.
– jgoldberger - MSFT
Nov 19 '18 at 22:13












That works for now. Thanks @jgoldberger
– micael cunha
Nov 22 '18 at 14:42






That works for now. Thanks @jgoldberger
– micael cunha
Nov 22 '18 at 14:42















0














You can play with the VerticalOptions and Aspect properties of the Image object to get the desired result.



Example :



var img = new Image() { 
Source = "picture.png",
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Aspect = Aspect.AspectFill
};





share|improve this answer





















  • That doesn't allow me to set max height
    – micael cunha
    Nov 19 '18 at 17:10










  • @micaelcunha, can you provide some code in your question?
    – chaosifier
    Nov 19 '18 at 17:11










  • I just have a image with AspectFit, I just wanna to set it with max height so that never be big than x.
    – micael cunha
    Nov 19 '18 at 17:20










  • Without looking at your code or xaml, it's going to be hard to help you.
    – chaosifier
    Nov 19 '18 at 17:23
















0














You can play with the VerticalOptions and Aspect properties of the Image object to get the desired result.



Example :



var img = new Image() { 
Source = "picture.png",
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Aspect = Aspect.AspectFill
};





share|improve this answer





















  • That doesn't allow me to set max height
    – micael cunha
    Nov 19 '18 at 17:10










  • @micaelcunha, can you provide some code in your question?
    – chaosifier
    Nov 19 '18 at 17:11










  • I just have a image with AspectFit, I just wanna to set it with max height so that never be big than x.
    – micael cunha
    Nov 19 '18 at 17:20










  • Without looking at your code or xaml, it's going to be hard to help you.
    – chaosifier
    Nov 19 '18 at 17:23














0












0








0






You can play with the VerticalOptions and Aspect properties of the Image object to get the desired result.



Example :



var img = new Image() { 
Source = "picture.png",
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Aspect = Aspect.AspectFill
};





share|improve this answer












You can play with the VerticalOptions and Aspect properties of the Image object to get the desired result.



Example :



var img = new Image() { 
Source = "picture.png",
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Aspect = Aspect.AspectFill
};






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 17:02









chaosifier

875726




875726












  • That doesn't allow me to set max height
    – micael cunha
    Nov 19 '18 at 17:10










  • @micaelcunha, can you provide some code in your question?
    – chaosifier
    Nov 19 '18 at 17:11










  • I just have a image with AspectFit, I just wanna to set it with max height so that never be big than x.
    – micael cunha
    Nov 19 '18 at 17:20










  • Without looking at your code or xaml, it's going to be hard to help you.
    – chaosifier
    Nov 19 '18 at 17:23


















  • That doesn't allow me to set max height
    – micael cunha
    Nov 19 '18 at 17:10










  • @micaelcunha, can you provide some code in your question?
    – chaosifier
    Nov 19 '18 at 17:11










  • I just have a image with AspectFit, I just wanna to set it with max height so that never be big than x.
    – micael cunha
    Nov 19 '18 at 17:20










  • Without looking at your code or xaml, it's going to be hard to help you.
    – chaosifier
    Nov 19 '18 at 17:23
















That doesn't allow me to set max height
– micael cunha
Nov 19 '18 at 17:10




That doesn't allow me to set max height
– micael cunha
Nov 19 '18 at 17:10












@micaelcunha, can you provide some code in your question?
– chaosifier
Nov 19 '18 at 17:11




@micaelcunha, can you provide some code in your question?
– chaosifier
Nov 19 '18 at 17:11












I just have a image with AspectFit, I just wanna to set it with max height so that never be big than x.
– micael cunha
Nov 19 '18 at 17:20




I just have a image with AspectFit, I just wanna to set it with max height so that never be big than x.
– micael cunha
Nov 19 '18 at 17:20












Without looking at your code or xaml, it's going to be hard to help you.
– chaosifier
Nov 19 '18 at 17:23




Without looking at your code or xaml, it's going to be hard to help you.
– chaosifier
Nov 19 '18 at 17:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378538%2fxamarin-forms-set-max-height-image%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith