I'm Working on Xamarin Forms project using Visual Studio 2017 , I want to show few texts in side label using different styles so i used span text as below but it gives me compile error "No property, bindable property, or event found for 'Text', or mismatching type between value and property." My code is below .
<Label TextColor="{Binding ColorStatus}" Margin="0,0,0,0" HorizontalTextAlignment="Start" FontSize="Medium">
<Label.FormattedText>
<FormattedString>
<Span Text="Thank you." FontAttributes="Bold"/>
<Span Text="You have tagged-" FontAttributes="Bold"/>
<Span Text= "{Binding ActivityName}" FontAttributes="Bold"/>
</FormattedString>
</Label.FormattedText>
</Label>
Update your Xamarin.Forms nuget package to the latest one. Bindable spans are available from Xamarin.Forms 3.1.0+ version.
More about releases and features you can find it here.
Related
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?
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>
I have a working app that displays images. I started a new app and copied the code but this new app does not display images. Puzzled, I have tried many, many things to debug it. I eventually made a plain vanilla new project with only an Image control. As usual, I added the picture to the project using Add Existing Item. I confirmed that the image is there. It does not display the image. I noticed something different in Solution Explorer. Under the Solution, the first project has Dependencies listed under it. This is new. My previous apps have never had that. Now every new project I create has it. I also noticed that the Properties of the image was Build Action of None. I tried changing it to Content but that did not help. At this point, I am baffled and stuck. Did something change in Visual Studio? Here is the image test XAML.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ImageTest"
x:Class="ImageTest.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Image Source="gr8oz.png" />
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
As I said, I have a working app that has been released. I copied this code into a new app and it does not work. In my investigation, I have found that the Image control does not work for me anymore.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:OFamV2"
Style="{StaticResource MyContentPage}"
x:Class="OFamV2.MainPage"
Title="Main Menus">
<ScrollView>
<StackLayout>
<Button x:Name="TreeButton"
Text="Don and Iola Osborne"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="TreeButton_Clicked" />
<Button x:Name="IndianNamesButton"
Text="Indian Names"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="IndianNamesButton_Clicked" />
<Button x:Name="NextPageButton"
Text="Indian Potpourri"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="NextPageButton_Clicked" />
<Button x:Name="OldPhotos"
Text="Old Photos"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="OldPhotos_Clicked" />
<Button x:Name="ReunionButton"
Text="Family Reunion"
VerticalOptions="Start"
Style="{StaticResource MyButtons}"
Clicked="ReunionButton_Clicked"
/>
<StackLayout Orientation="Horizontal">
<Image
Source="Photos/gr8oz.png"
Style="{StaticResource MyImage}"
Margin="0,30,0,0"
Aspect="AspectFit"
HorizontalOptions="End"
/>
<Image
Source = "Photos/logo.bmp"
Style="{StaticResource MyImage}"
Margin="150,0,0,0"
HeightRequest="200"
WidthRequest="200"
HorizontalOptions="End"/>
</StackLayout>
</StackLayout>
</ScrollView>
</ContentPage>
I have searched and read everything that I can find (and yes, I have read the Microsoft doc about the Image class).
I am also curious why Dependencies suddenly appeared in the Shared Project folder. This is new too. How do I resolve them? See screenshot.
Dependencies under OFamV2.
I uninstalled Visual Studio, deleted the folder, reinstalled Visual Studio Community 2017 Version 15.8.8 and the problem is still there, even with a new project.
For Options, I select Cross Platform/ Mobile App/ Platform: Android and UWP/Code Sharing: .Net Standard.
Set image show you can see here , i think you have used that.
So reload your project,and rebuild it,you can try this.
More info:
Here is a similar disscussion about image show.
Suggest that better not copy code from other project about view,they may result some problems where you do not know.
I have an IOS Application with embedded Xamarin Forms. I created a simple view with buttons and want to set the height of these buttons depending on the platform. This is my code:
<Button Text="{Binding SendFeedbackButtonText}"
Command="{Binding SendEarlyFeedbackCommand}"
HorizontalOptions="FillAndExpand"
Margin="3,0,3,0" >
<Button.Effects>
<effects:PrimaryButtonEffect />
</Button.Effects>
<Button.HeightRequest>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS" Value="37"/>
</OnPlatform>
</Button.HeightRequest>
</Button>
But this gives me the following error in build:
No property, bindable property, or event found for 'HeightRequest', or mismatching type between value and property.
When I set HeightRequest fix in the button tag it works.
Xamarin.Forms version: 2.5.0.121934
Also I created a new blank App with Xamarin.Forms and .net standard 2.0 to try this out. It works as long as you don't have the XamlCompilation Attribute set:
[XamlCompilation(XamlCompilationOptions.Compile)]
You can find the project here: https://github.com/NPadrutt/FormsButtonIssueTestProject
What am I doing wrong?
Depending on your version of Forms try switching it to this instead
<Button.HeightRequest>
<OnPlatform x:TypeArguments="x:Double" iOS="37"/>
</Button.HeightRequest>
or
<Button.HeightRequest>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS">37</On>
</OnPlatform>
</Button.HeightRequest>
Having followed Laurent's upgrade guide http://www.galasoft.ch/mvvm/installing/mangobeta/ to get from an existing MVVMLight WP7 project to a WP71 project. I have changed the references and namespaces corectly. But the EventTrigger is not recognised in the XAML
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<cmd:EventToCommand
Command="{Binding Mode=OneWay, Path=LoadedCommand}"
PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
I get an error on the EventTrigger element.
Has it changed?
I had this exact same problem when I upgrade my application from WP7 to WP7.1(Mango). The problem was the MVVM Light Binaries. You need to upgrade to the WP7.1 Binaries.
Laurent Bugnion ( https://stackoverflow.com/users/12233/lbugnion ) explains how to upgrade the MVVM Light binaries on his website here: http://www.galasoft.ch/mvvm/installing/mangobeta/
These are the essential steps I used to fix my problem:
Download the most recent version from here.
Open and Compile the WP71 project.
Copy the binaries to your MVVM Binary location (in my case C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries)
Open your project
In the References folder, delete GalaSoft.MvvmLight, GalaSoft.MvvmLight.Extras and System.Windows.Interactivity.
Add the new references from the folder C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\WP71.
I had a similar problem after upgrading to Mango. In my case, I had the EventToCommand binding on a MenuItem click, but you seem to have it on some sort of loaded event. You could try using an anonymous delegate in the loaded evcent from the view's code-bhind. Ie:
this.Loaded+=(s,e)=>ViewModel.LoadedCommand.Execute(null);
In my case, I changed from:
<tk:MenuItem Header="Delete Snapshot" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<mvvmLight:EventToCommand Command="{Binding DeleteSnapshotCommand, Mode=OneWay}" CommandParameter="{Binding SelectedItem,ElementName=lstSnapshots}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</tk:MenuItem>
to
<tk:MenuItem Header="Delete Snapshot" Command="{Binding DeleteSnapshotCommand, Mode=OneWay}" CommandParameter="{Binding SelectedItem,ElementName=lstSnapshots}" />
I have moved on from this issue, by reverting back to pre-mango dev environment.
Not the solution I wanted, but - onwards and forwards.