Image Uri does not appear in XAML - windows-phone-7

I don't understand the problem : I have a link of an image but it does not visible :
<Image Source="http://www.bestofleboncoin.fr/img/adsok/thumbs/304409998.jpg" Margin="0,10,0,0" />
if I download this picture and save it in the solution it's ok !
<Image Source="/304409998.jpg" Margin="0,10,0,0" />
If I upload on my personal website, this image is visible too..

Can you download it using WebClient and then display it inside your control? Besides, you are supposed to just that for performance reasons.
It appears as if the site in question forbids direct linking.

I have a little solution but I don't know about performances ....
<phone:WebBrowser Name="Browser" Source="{Binding Links[1].Uri}" />

Related

Uno platform: load xaml image from Assets

For the Uno platform, I would like to load an image (PNG) from Assets, using XAML. Further, I'd like to use a single image for all target platforms and have it scale to the size of its container.
Is this possible ?
I have succeeded to do this for UWP and Wasm with the following syntax:
<Image Source="Assets/icons/arrow_back_white.png" />
However, for Android, no image is displayed, I just see my background color.
I realize that the proper approach is to provide separate images for each target platform and, optionally, separate images for each resolution in each platform. That is a nice ideal but I am trying to avoid that enormous development overhead, at least for now.
Thanks.
EDIT:
First, to be extra clear, I do have Content selected for my images.
I'm getting a worse failure when using AppBarButton, e.g.:
<CommandBar>
<AppBarButton Icon="arrow_back_white.png" Label="Back" Click="OnBackClicked" />
<AppBarButton Icon="arrow_back_white.png" Label="Page" Click="OnPageClicked" />
<AppBarButton Icon="more_menu_white.png" Label="More" Click="OnMoreMenuClicked"/>
</CommandBar>
This fails for UWP during app initialization with an error:
Failed to create a 'Windows.UI.Xaml.Controls.IconElement' from the text 'arrow_back_white.png'.
It also fails with a build error for Wasm and Android.
It doesn't matter if I put the icon files directly in the Assets directory or a nested directory.
What is the correct syntax and configuration to reference icons and images ?
EDIT 2:
Still doesn't work for Android, but does work for UWP and Wasl. I moved my images into the Assets directory and have this XAML:
<Button
Width="25" Height="25"
Padding="5"
Click="OnBackClicked" >
<Image Source="ms-appx:///Assets/arrow_back_white.png" Height="100" Width="100" />
</Button>
<Button
Width="25" Height="25"
Padding="5"
Click="OnPageClicked" >
<Image Source="ms-appx:///Assets/crop_din_white.png" />
</Button>
<Button
Width="25" Height="25"
Padding="5"
Click="OnMoreMenuClicked" >
<Image Source="ms-appx:///Assets/more_menu_white.png" />
</Button>
All three buttons show up as blank grey approx 1cm high and wide.
EDIT 3
Tried with a newly created default app, which works. The only change I made to the code is to MainPage.xaml by removing the grid and adding:
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
<Button
Width="25" Height="25"
Padding="5" >
<Image Source="ms-appx:///Assets/arrow_back_white.png" Height="100" Width="100" />
</Button>
<Button
Width="25" Height="25"
Padding="5" >
<Image Source="ms-appx:///Assets/crop_din_white.png" />
</Button>
<Button
Width="25" Height="25"
Padding="5" >
<Image Source="ms-appx:///Assets/more_menu_white.png" />
</Button>
</StackPanel>
So, now, the arduous task of finding the significant difference(s).
I had a similar issue and here is how I resolved it. I used the following:
<Image Source="ms-appx:////Assests/yourimage.png">
The other thing I did- you probably have done this already- but I had to put a transparent border around it. Hopefully this is helpful!
Let's say you have a Directory under the Shared Project called Assets and inside you have an image called wasm_logo.png.
As Jt6 indicated you should be able to use that image for all the different platforms Uno supports, including Android by using this:
<Image Source="ms-appx:///Assets/wasm_logo.png" Height="300" Width="300"/>
Note: If you have a nested Directory, another directory inside Assets, you just need to add it as part of the path.
<Image Source="ms-appx:///Assets/Icons/wasm_logo.png" Height="300" Width="300"/>
The code above will work if your wasm_logo.png image is inside an Icons Directory which is inside the Assets directory.
Considerations:
Images should be marked as Content (you already validated this)
To Scale for different sizes Uno Supports (as UWP) different Assets qualifiers. Let's say that the same image you want to support 3 different sizes, then you would these 3 files inside the Assets Directory:
wasm_logo.scale-100.png
wasm_logo.scale-300.png
wasm_logo.scale-500.png
For Android these are translated into mdpi, xhdpi and xxhdpi. But the best part is that to use it you do not need to specify the size and with the same code as above you will get the same result.
<Image Source="ms-appx:///Assets/wasm_logo.png" Height="300" Width="300"/>
Note: For Android when you do not specify any qualifier the Images is treated as nodpi
More about Assets and qualifiers can be read here.
If the above is still not working try updating your Uno.Platform to the latest version.
You could also validate that no errors are being reported on the Visual Studio Output Window when running the app.
As a final thing, you could try checking if the images are being moved correctly at compile time. You can do this by building your Android project and then opening the File Explorer at this route:
ProjectName\ProjectName.Droid\obj\Debug\100\res
Inside there you should find the Drawable Directories for Android.
Following the first example, your image should be in the Drawable-nodpi folder
Hope this is useful.
Andres
App Runining
I am sorry that did not help. Just checking something obvious- did you add the picture to the Shared Project Assets folder?

Xamarin.Forms Images not showing

I am developing a Cross-Platform app in Xamarin Visual Studio 2019 and having issues with image display.
I am trying to show an image with the following XAML code.
<StackLayout Grid.Row="0" Grid.Column="0" Spacing="0" >
<Image
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Source="logo"
WidthRequest="{OnPlatform iOS=300, Android=250}">
</Image>
</StackLayout>
Problem is image not displaying on either preview or deployed app.
I took references from multiple forums including help from StackOverflow but couldn't tackle the issue.
Here are the points and methods I worked on to resolve the issue.
The file named logo is an android resource folder and is a proper .png file.
Property for the file is set to AndroidResource.
As per answers posted here, Xamarin Images not showing, file name does not have a hyphen in it, and also tried other posted answers on the same page.
Image size 307X80 pixels so it's well within range for memory or size.
Android Drawable folder also contain default xamarin_logo.png image and that file works fine. But not newly added images. Is there anything I am missing here to add these image files to the solution?
Either the image extension or image path or the build action for the image seems to be the problem in your case. I tried your code and got that working fine for both png and jpg images.
<StackLayout Spacing="0">
<Image HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
Source="github.png" WidthRequest="{OnPlatform iOS=300, Android=250}" />
<Image HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
Source="githubb.jpg" WidthRequest="{OnPlatform iOS=300, Android=250}" />
</StackLayout>
Note: I have removed the grid.row and grid.column indexing as I am not using my StackLayout inside a grid.
Please make sure whether you have kept your images directly inside the drawable folder in the Resources in Android. If not, you may have to give the Source name as FolderName\ImageName.Extension.
Refer below link for more details:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#local-images
Also, please ensure whether the BuildAction of your image is AndroidResource and Custom Tool is MSBuild:UpdateGeneratedFiles. Please refer to the below image.
I got the below output for the code which I posted above.
I hope that helps.
Your XAML code is Correct but you have missed the image extension .png you must define your image Extension(format) Ex: (image.png or image.jpeg) That is the reason the image is not displayed.
<StackLayout Grid.Row="0" Grid.Column="0" Spacing="0" >
<Image
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Source="logo.png"
WidthRequest="{OnPlatform iOS=300, Android=250}">
</Image>
</StackLayout>

Xamarin.Forms PCL cannot show image

I'm learning Xamarin.Forms PCL. I want to load image on page, i tried to load image with uri, that's OK. But i add image into project, it's don't work.
<StackLayout Margin="0,20,0,0">
<Image x:Name="img" Source="mario.jpg"/>
<Button x:Name="btnRotate" Clicked="btnRotate_Clicked" Text="Rotate" />
</StackLayout>
Any help is appreciated. Thanks!
You can not include dashes or spaces in image names for Android compatibility
Rename your image from piotr-chrobot-276746.jpg to something else, like piotrchrobot.jpg
https://developer.xamarin.com/guides/android/application_fundamentals/resources_in_android/part_1_-_android_resource_basics/
Don't forget to set the Build action to AndroidResource.

Windows phone ads not working

I am trying to integrate ads into a already successful deployed app. However no matter what I do, I cannot seem to get the ads working. I have tried using both the code version and the drag n' drop gui version. Neither of which I can get to work.
This is what I see: When it starts up it may flash for a split second white, where the ad is supposed to be, but none the less, no adds. It recognizes that it is where I place it, when I place it over a button, the button becomes unclickable. All being said, no default "microsoft advertising" image pops up. I have installed the ad SDK and have successfully been able to make the ads display in other project with ease.
What gives? This is very simple page and I cannot figure out what is wrong. It also seems that I cannot place an ad on any of the other pages either... I do have the Microsoft.Advertising.Mobile and Microsoft.Advertising. Mobile.UI included in the project and my internet is working (I have an project open at the same time with ads and it works)
<phone:PhoneApplicationPage
x:Class="AppName.AdPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"
xmlns:my="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Margin="12,17,12,28">
<TextBlock x:Name="PageTitle" Text="Thank You!" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Width="334" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0" Height="569" VerticalAlignment="Top">
<Button Content="Ok" Height="72" HorizontalAlignment="Center" Margin="0,428,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
<my:AdControl AdUnitId="Image480_80" ApplicationId="test_client" Height="80" HorizontalAlignment="Left" Margin="-12,458,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
</Grid>
</Grid>
</phone:PhoneApplicationPage>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Advertising.Mobile.UI;
using Microsoft.Advertising.Mobile;
namespace Stickey_Note_v._1
{
public partial class AdPage : PhoneApplicationPage
{
public AdPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
}
I had the same issue and wrote a blog post about it. Here's the important stuff:
The symptoms of a problem with the SDK's AdControl seem to be pretty consistent: The page loads, the control flickers briefly, showing the hint of a 1 pixel frame, and then, poof. It collapses into nothingness, leaving only a black hole of dispair.
In theory, setting up the AdControl is simple. The documentation from Microsoft outlines the basics:
Download and install the Microsoft Advertising SDK.
Add a reference to Microsoft.Advertising.Mobile.UI.
Drag the control onto the page in the Visual Studio designer.
Set the AdUnitId and ApplicationId properties to either test values or actual live values, which you can obtain from Microsoft pubCenter.
But it couldn't be that easy. I followed the documentation carefully, but nothing was working. I couldn't even get test ads to show up, which seemed really weird. I even reverted to an older version of my app (yay source control!) and dropped in the new .dll. Failure.
Finally, I found a clue in an obscure forum post.
The Microsoft documentation neglects to mention several important details. You need to pay particular attention to the following if you're upgrading an existing project to the Mango ad SDK, as I was:
You must specify a height and width for the AdControl. Failing to specify the Height and Width attributes, or setting them to auto, will cause tears of frustration. I'd recommend 80 pixels high and 480 pixels wide, as that's the native size of the ads that Microsoft serves up.
It seems that you can't have two AdControls on the same page, or at least not in the same parent element. The second one will collapse. There might be a way around this, but I discovered it while building my demo app and didn't care to pursue a solution.
You must must must specify certain capabilities in your WMAppManifest.xml file. Since I was upgrading my app, I didn't have some of the newer capabilities declared. The one that was causing all the trouble was ID_CAP_IDENTITY_USER. The following capabilities are all required for the control to function correctly:
<Capabilities>
<Capability Name="ID_CAP_IDENTITY_USER"/>
<Capability Name="ID_CAP_MEDIALIB"/>
<Capability Name="ID_CAP_NETWORKING"/>
<Capability Name="ID_CAP_PHONEDIALER"/>
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/>
</Capabilities>
Hope that helps!
I think your problem could come from (if you didn't remove it for posting it here):
<my:AdControl AdUnitId="Image480_80" ApplicationId="test_client" Height="80" HorizontalAlignment="Left" Margin="-12,458,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
</Grid>
You have to use AdUnitId and ApplicationId which you get from pubCenter.
One more think to note for those still struggling
xmlns:ads="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI"
<ads:AdControl Height="80"
Width="480"
AdUnitId="Image480_80"
ApplicationId="test_client" />
As in example. Declaring ads and the namespace is super important.
In my project i just inserted the adcontrol part alt + enter for resharper to do the rest of the work which he didnt. He replaces ads with UI and there was no error compilation still the ads wouldn't show. When i declared ads myself and changed the adcontrol namespace. Everything worked fine.

WinPhone Xaml Grid.Background relative path

I'm trying to set the background to a windows phone page in Xaml. I'm probably missing something really obvious but I can't seem to get this to show unless the page and background are in the same folder. What I want however is my page to be in a views folder and my background to be in a resources folder. This is what I have at the minute:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Background>
<ImageBrush ImageSource="\\Resources\MMCRBackground.png" Stretch="UniformToFill"/>
</Grid.Background>
</Grid>
There is no error saying that the path doesn't exist? Any ideas?
Thanks.
From memory I think you want
<ImageBrush ImageSource="/Resources/MMCRBackground.png" Stretch="UniformToFill"/>
Where the MMCRBackground.png has a build action of Content (not resource) in the properties from the Solution Exporer

Resources