Hi,
I am completely new to programming. I installed visual studio 2022 and I am following the video's for beginners that the program gives. So far that goes well but now I am making the "note app" from the video, I get ideas of things I want to try and learn myself. One of those things is making a background, not just a color but a picture of my own that I made with photoshop. I would like it to be the whole background, not just a part of a grid.
I looked up several tutorials and some fora but nothing of the codes is working. And since it is al new, it is difficult to figure out why it doesn't working.
one of the codes I tried:
<Grid>
<Image
x:Name="backgroundImage"
Source="image_source.png"
Aspect="AspectFill"
HorizontalOptions="Start"/>
</Grid>
I added my picture in the folder (that was explained in the movie so that should have been correct) and I changed the name in de code to the name of my picture.
and than they said to put the next in the code behind
protected override void OnSizeAllocated (double pageWidth, double pageHeight) {
base.OnSizeAllocated(pageWidth, pageHeight);
const double aspectRatio = 1600 / 1441.0; // Aspect ratio of the original image
backgroundImage.WidthRequest = Math.Max(pageHeight * aspectRatio, pageWidth);
}
So when I put in the first part, I could just debug with no errors but there did not came any picture as background. When I added the second part I got errors but now I wanted do take the same steps again to show you the errors, they are gone. It was something like "onsizeallocated" did not excisted.
I tried some other video's but haven't find a place where they can explain me how to work with background images for an android app.
I think I need to define some things or be specific on the location or something like that but I don't really know what exactly.
So, is there someone how can explain to me how this works? How can I use an image as background for my app?
Thank you!
I am completely new to programming. I installed visual studio 2022 and I am following the video's for beginners that the program gives. So far that goes well but now I am making the "note app" from the video, I get ideas of things I want to try and learn myself. One of those things is making a background, not just a color but a picture of my own that I made with photoshop. I would like it to be the whole background, not just a part of a grid.
I looked up several tutorials and some fora but nothing of the codes is working. And since it is al new, it is difficult to figure out why it doesn't working.
one of the codes I tried:
<Grid>
<Image
x:Name="backgroundImage"
Source="image_source.png"
Aspect="AspectFill"
HorizontalOptions="Start"/>
</Grid>
I added my picture in the folder (that was explained in the movie so that should have been correct) and I changed the name in de code to the name of my picture.
and than they said to put the next in the code behind
protected override void OnSizeAllocated (double pageWidth, double pageHeight) {
base.OnSizeAllocated(pageWidth, pageHeight);
const double aspectRatio = 1600 / 1441.0; // Aspect ratio of the original image
backgroundImage.WidthRequest = Math.Max(pageHeight * aspectRatio, pageWidth);
}
So when I put in the first part, I could just debug with no errors but there did not came any picture as background. When I added the second part I got errors but now I wanted do take the same steps again to show you the errors, they are gone. It was something like "onsizeallocated" did not excisted.
I tried some other video's but haven't find a place where they can explain me how to work with background images for an android app.
I think I need to define some things or be specific on the location or something like that but I don't really know what exactly.
So, is there someone how can explain to me how this works? How can I use an image as background for my app?
Thank you!