Can I pass Android styles in parameters with Xamarin.Forms XAML - xamarin

Is there a way (without using a renderer) that I can set styling for Android switches in a way like this:
<Switch android:colorControlActivated="#FF00FF"
HorizontalOptions="End" VerticalOptions="Center"
IsToggled="{Binding PbSwitch}" />

No. It is shared logic, you can't use platform spec staff there without abstraction. Why does renderer not suit you?

Related

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>

To create SlidingupPanel like googleMaps for both android and IOS

Do you know how to create a SlideUpPanel like GoogleMaps for both Android and iOS using Xamarin?
If I use SliddingupPanel layout is only for android
Help me, please.
I would suggest you use DKSlideUpPanel
It's easy to use and fast
Steps:
First, simply reference the NuGet package in your Xamrin.Forms projects.
Second, initialize SlidingUpPanel instance either in XAML or C#.
Lastly, apply the SlidingPanelConfig for your customizations.
How to use:
Add a mainView something like this;
<DK:SlidingUpPanel x:Name="spTest">
<DK:SlidingUpPanel.MainView>
<StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
**MainDesign**
</StackLayout>
</DK:SlidingUpPanel.MainView>
Set panel ratio and if you want the toolbar visible:
<DK:SlidingUpPanel.PanelRatio>0.4</DK:SlidingUpPanel.PanelRatio>
<DK:SlidingUpPanel.HideNavBar>True</DK:SlidingUpPanel.HideNavBar>
Check the following guide for an even better understanding of how it works:
https://www.c-sharpcorner.com/article/xamarin-forms-slideuppanel-app/

Is it possible to use Image Set in a Xamarin Forms

I am trying to add some Images as Image Sets in a Xamarin.Forms project. I followed this guide . But the icon is not displayed. Is it possible actually to use Image Sets in a Xamarin Forms Solution for the iOS project?
<Image VerticalOptions="Center"
HorizontalOptions="End"
Source="check_outline_500_active.png"
WidthRequest="40">
</Image>
Yes you can.
create the Asset catalog
add Image Set and name it "check_outline_500_active" (without .png)
add the images
done
my xaml
<Image VerticalOptions="Center"
HorizontalOptions="Center"
Source="check_outline_500_active.png">
</Image>
Result
Note
You might have to delete mtbs (on the mac) and bin/obj (on your project) or the build cache can fool you :)
Try to add images in resources folder under xamarin ios project and rename file like :
check_outline_500_active.png,
check_outline_500_active#2x.png,
check_outline_500_active#3x.png
but in code use : check_outline_500_active.png

Image Uri does not appear in XAML

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}" />

Detecting and Implementing Scrollbar Style in Window 8/RT Application

I am developing a Custom Control to be placed inside a ScrollViewer, I have Custom coded a generic.xaml for applying visual style for the Scrollviewer.
<ScrollBar x:Name="VerticalScrollBar"
Grid.Row="0"
Grid.Column="1"
Width="18"
Margin="0,-1,-1,-1"
IndicatorMode="TouchIndicator"
IsTabStop="False"
Maximum="{TemplateBinding ScrollableHeight}"
The Problem I am facing is, I need to set the IndicatorMode to TouchIndicator/MouseIndicator based on whether the user is using Touch Devices or not.
Is there a way to do it?
Thanks
Arun Selva Kumar. B
Used Visual State Manager to achieve the requirement.

Resources