For my application, I need to have a video player below the canvas view (in xamarin forms). The problem with this, however, is users cannot use the built in player controls because the canvas is swallowing those events. My question is, is it possible to allow touch passthrough on the canvas so when the user clicks play, the video will play?
Touch passthrough to video player below canvas
ListView inside CarouselView scroll vertical is almost impossible.
I have a collection of listviews inside a horizontal CarouselView. When im trying to scroll vertically through the listview in focus, if make any tiny movement horizontally, the carousels horizontal scrolling "takes over" and makes scrolling vertically almost impossible. Anyway i can "prioritize" the listviews scrolling?
Hope it makes sense
Metadata file could not be found
I was trying to solve x:Name problem (The name "blablabla" Does not exist in current context ) . I cleaned up and rebuild the solition but it didnt work. Then i manually clean obj and bin files it didnt work also and i have got new errors now. How can i deal with :
How to set a property of a control in ControlTemplate
In Xamarin Forms: If I have a ControlTemplate
like this:
<ContentView.ControlTemplate>
<ControlTemplate>
<Grid Margin="0" Padding="0">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Entry x:Name="ThisEntry1"/>
<!--Some other Entries-->
</Grid>
</ControlTemplate>
</ContentView.ControlTemplate>
Then I used this ControlTemplate
in a ContentPage
like this:
Wrong Code:
<ContentPage.Content>
<FlexLayout>
<entry:MyEntryFromThatTemplage
Text="???" <<< How to retreive ThisEntry1 and set its Text property here?
/>
In https: // docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/templates/control-templates/creating I can get the Entry
this set its Text
at runtime using GetTemplateChild("ThisEntry1")
but I want to get it in XAML
How do i put an image over other image
I have an image in my App. How can i put other image over it. This new image is a retangle with rounded boder and inside it a label. How can i do this?
Using the Minimum Width for CollectionView
I have a CollectionView which I want to use the minimum necessary width. The containing Grid has the following ColumnDefinitions:
<Grid.ColumnDefinitions><ColumnDefinition Width="Auto"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions>
And the code for the CollectionView is as follows:
<d:CollectionView.ItemsSource>
1
2
3
4
5
6
7
8
9
10
11
12
</d:CollectionView.ItemsSource>
<CollectionView.ItemTemplate>
Issue setting colors in XF
I am having some issues with setting the status bar color and the selected tab underline color in xamarin forms, especially android.
Status Bar
I thought that setting the colorPrimaryDark would set the status bar background color:
<item name="colorPrimaryDark">@color/primaryDark</item>
Which i set to yellow as a test, but instead it look black, with no text. If I swipe down from the top of the screen then somehow the text (time, battery, carrier etc show).
Tab Underline
I do this but the tab underline is still white:
<!--Selected tab underline-->
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/accent</item>
</style>
How can I fix this? How do I set the tab underline color and the status bar color in android and iOS?
Thanks
Linker error after adding Xamarin.Google.iOS.MobileAds nuget
Hi
I was following this tutorial : https://montemagno.com/xamarinforms-google-admob-ads-in-ios/
and once I added the Nuget package i got the following linker error:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(842,3): error : warning: directory not found for option '-FFAdM-7.47.0/Frameworks/GoogleMobileAdsFramework-Current'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(842,3): error : framework not found GoogleMobileAds
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(842,3): warning MT5215: References to 'System' might require additional -framework=XXX or -lXXX instructions to the native linker
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(842,3): error MT5201: Native linking failed. Please review the build log and the user flags provided to gcc: -ObjC -lz -lsqlite3
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(842,3): error MT5202: Native linking failed. Please review the build log.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(842,3): warning : directory not found for option '-FFAdM-7.47.0/Frameworks/GoogleMobileAdsFramework-Current'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(842,3): error : linker command failed with exit code 1 (use -v to see invocation)
I saw some threads about something similar but could not resolve this.
Any ideas?
Thanks
POST Failed at Xamarin.UITest.Shared.Http.HttpClient.HandleHttpError
Hi,
I have the following error and I have no idea what it means. It does not happen in the emulator--only when it runs on a physical phone (or in appcenter with 'Test on a real device' enabled).
1) Error : AppCenter.UITest.Android.Tests.AppDoesLaunch
System.Net.WebException : POST Failed
at Xamarin.UITest.Shared.Http.HttpClient.HandleHttpError (System.String method, System.Net.Http.HttpResponseMessage response, Xamarin.UITest.Shared.Http.ExceptionPolicy exceptionPolicy) [0x00052] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Shared.Http.HttpClient.SendData (System.String endpoint, System.String method, System.Net.Http.HttpContent content, Xamarin.UITest.Shared.Http.ExceptionPolicy exceptionPolicy, System.Nullable1[T] timeOut) [0x00123] in <18ae7883e2424c558186d1d9edf9f14b>:0 at Xamarin.UITest.Shared.Http.HttpClient.Post (System.String endpoint, System.String arguments, Xamarin.UITest.Shared.Http.ExceptionPolicy exceptionPolicy, System.Nullable
1[T] timeOut) [0x00014] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Shared.Android.HttpApplicationStarter.Execute (System.String intentJson) [0x00035] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Shared.Android.AndroidAppLifeCycle.LaunchApp (System.String appPackageName, Xamarin.UITest.Shared.Android.ApkFile testServerApkFile, System.Int32 testServerPort) [0x000a1] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Shared.Android.AndroidAppLifeCycle.LaunchApp (Xamarin.UITest.Shared.Android.ApkFile appApkFile, Xamarin.UITest.Shared.Android.ApkFile testServerApkFile, System.Int32 testServerPort) [0x00007] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Android.AndroidApp..ctor (Xamarin.UITest.Configuration.IAndroidAppConfiguration appConfiguration, Xamarin.UITest.Shared.Execution.IExecutor executor) [0x00193] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Android.AndroidApp..ctor (Xamarin.UITest.Configuration.IAndroidAppConfiguration appConfiguration) [0x00000] in <18ae7883e2424c558186d1d9edf9f14b>:0
at Xamarin.UITest.Configuration.AndroidAppConfigurator.StartApp (Xamarin.UITest.Configuration.AppDataMode appDataMode) [0x00017] in <18ae7883e2424c558186d1d9edf9f14b>:0
at AppCenter.UITest.Android.Tests.SetUp () [0x00010] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <48b95f3df5804531818f80e28ec60191>:0
Xamarin Forms 4.3.0.908675 Device Open Uri
Hi everyone !
I have now updated my project to xamarin forms 4.3.0.908675. Before updating, I was using device.openUri (https: example.com) to redirect the user to the browser and it worked fine. But, after the update this code(Device.OpenUri) did not work. Probably this code in this version of xamarin forms deprecate.
I found the following to solve this;
- Launcher.TryOpenAsync()
- Launcher.CanOpenAsync()
- Launcher.OpenAsync()
What kind of solution should I apply? Looking forward to your valuable suggestions.
Thanks in advance !
How to find the cause of: Xamarin.Forms targets have been imported multiple times
I'm working my way thru the book "Creating Mobile Apps with Xamarin Forms" and a lot of the sample code requires some work to get it running, which is all very educational and helps me learn and remember. However I can't find the cause of this one;
Chapter 20, MandelbrotProgress, gives me an error in the Xamarin.Formsbook.Toolkit project:
Xamarin.Forms targets have been imported multiple times. Please check your project file and remove the duplicate import(s).
Can somebody point me at the root cause of this please. I cannot find any obvious duplicates in the project file, but there are some error conditions defined in there which I am suspicious of.
Also, is there a specific forum or support area for the above mentioned book?
How to execute javascript code in html source of Webview?
My app receives articles from wordpress, through a converter I clean the html code and then with StringBuilder I create the new html string that I feed to a WebView, here I'd like to add an ADV javascript widget (the script is external). Do you believe it is possible?
How to set shell bottom tab title fontsize without animation and top tab text lowercase?
Please Help
Reading from Bluetooth freezes the app
Recently I have been building an app that allows Bluetooth communication. I have been following this documentation and I got the connection working. Since it is a blocking call the popup message disapears when another person clicks connect. But now I cant find the error when receiving. The sending doesnt post an error. But when checking if receive returns a value, both apps run unresponsive without any error or crash. I call the code with buttons like this (with dependency service):
`private void SendData(object sender, EventArgs e)
{
string test = "Testing";
byte[] temp = Encoding.ASCII.GetBytes(test);
DependencyService.Get<BluetoothManager>().write(temp);
}
private void CheckButton(object sender, EventArgs e)
{
if (DependencyService.Get<BluetoothManager>().read() != null)
{
CheckTxt.Text = "Ok";
}
}`
The CheckButton is used to only check if something was returned.
And then this is my entire Bluetooth class:
` using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Bluetooth;
using Xamarin.Forms;
using ShareTheMusic.Droid;
using Java.Util;
using System.IO;
[assembly: Dependency(typeof(BluetoothManagerService))]
namespace ShareTheMusic.Droid
{
public class BluetoothManagerService : BluetoothManager
{
BluetoothAdapter btAdapter = BluetoothAdapter.DefaultAdapter;
BluetoothServerSocket mServerSocket = null;
BluetoothSocket mSocket = null;
BluetoothDevice mDevice = null;
UUID uuid = UUID.FromString("30324d3a-3050-4e87-a159-f8fa6c433786");
Stream mmInStream;
Stream mmOutStream;
byte[] mmBuffer = null;
public string checkBluetooth(bool permition)
{
if (btAdapter == null)
{
return "NoBluetooth";
}
else
{
if (btAdapter.IsEnabled == false && permition != true)
{
return "TurnOnBluetooth";
}
else if(permition == true)
{
btAdapter.Enable();
return "AlreadyOn";
}
else
{
return "AlreadyOn";
}
}
}
public string[] findBTdevices()
{
string[] deviceNames = null;
deviceNames = (from qr in BluetoothAdapter.DefaultAdapter.BondedDevices select
qr.Name).ToArray();
return deviceNames;
}
public string discoverDevices()
{
return "not implemented yet";
}
public void acceptThread()
{
BluetoothServerSocket temp = null;
try
{
temp = btAdapter.ListenUsingRfcommWithServiceRecord("ShareTheMusic", uuid);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Socket's listen() method failed", ex);
}
mServerSocket = temp;
}
public void runServerSide()
{
acceptThread();
BluetoothSocket socket = null;
while (true)
{
try
{
socket = mServerSocket.Accept();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Socket's accept() method failed", ex);
}
if (socket != null)
{
manageConnectedSocket(socket);
mServerSocket.Close();
break;
}
}
}
public void ConnectThread(BluetoothDevice device)
{
BluetoothSocket temp = null;
mDevice = device;
try
{
temp = device.CreateRfcommSocketToServiceRecord(uuid);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Socket's create() method failed", ex);
}
mSocket = temp;
}
public void runClientSide(string deviceName)
{
BluetoothDevice tmp = (from qr in BluetoothAdapter.DefaultAdapter.BondedDevices where
qr.Name == deviceName select qr).FirstOrDefault();
ConnectThread(tmp);
try
{
mSocket.Connect();
}
catch (Exception ex)
{
try
{
mSocket.Close();
}
catch (Exception)
{
System.Diagnostics.Debug.WriteLine("Could not close the client socket", ex);
}
}
manageConnectedSocket(mSocket);
}
public void cancel()
{
try
{
mSocket.Close();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Could not close the connect socket", ex);
}
}
/*---------------------*/
public void manageConnectedSocket(BluetoothSocket socket)
{
mSocket = socket;
Stream tmpIn = null;
Stream tmpOut = null;
try
{
tmpIn = socket.InputStream;
}
catch (IOException ex)
{
System.Diagnostics.Debug.WriteLine("Error occurred when creating input stream", ex);
}
try
{
tmpOut = socket.OutputStream;
}
catch (IOException ex)
{
System.Diagnostics.Debug.WriteLine("Error occurred when creating output stream", ex);
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
}
public List<byte[]> read()
{
mmBuffer = new byte[1024];
int numBytes;
List<byte[]> intBytes = new List<byte[]>();
while (true)
{
try
{
numBytes = mmInStream.Read(mmBuffer);
intBytes.Add(BitConverter.GetBytes(numBytes));
}
catch (IOException ex)
{
System.Diagnostics.Debug.WriteLine("Input stream was disconnected", ex);
break;
}
}
return intBytes;
}
public void write(byte[] bytes)
{
try
{
mmOutStream.Write(bytes);
}
catch (IOException ex)
{
System.Diagnostics.Debug.WriteLine("Error occurred when sending data", ex);
}
}
}
}`
Xamarin forms: Previous screen is showing behind the current screen of ios app.
Found the same issue here. But the solution there not help me out.
Please have a look at the following screenshot of my xamarin forms ios app.
My problem is the previous page is showing behind the current screen. I am using visual studio for mac and Xcode 11.2.1 for development.
How can I get the fullscreen view for pages?
Make PanGestureRecognizer and ScrollView working together on Android
Hello everyone !
It seems that PanGestureRecognizer and ScrollView are not working together on Android.
I use them in a listview.
With PanGesture I need to detect the gesturetap and scrollview to scroll my content.
Is there a way to do this with a custom renderer for Android ?
Thanks !
Custom Entry Renderer: Changing Property does not effect UI with MVVM
Hello guys,
I have a Custom Entry Renderer:
`
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Retailer.CustomControl
{
public class TextBox : Entry
{
public static readonly BindableProperty BorderVisibilityProperty = BindableProperty.Create("BorderVisibility", typeof(bool), typeof(TextBox), false, BindingMode.TwoWay);
public bool BorderVisibility
{
get
{
return (bool)GetValue(BorderVisibilityProperty);
}
set
{
SetValue(BorderVisibilityProperty, value);
}
}
public new event EventHandler Completed;
public void SendComplete()
{
Completed?.Invoke(this, EventArgs.Empty);
}
}
}
`
in a rg.Xamarin.Pupup Page.
`
<?xml version="1.0" encoding="UTF-8"?>
<Grid VerticalOptions="Center" HorizontalOptions="Center">
<ScrollView>
<StackLayout VerticalOptions="Center" HorizontalOptions="Center" BackgroundColor="WhiteSmoke" Padding="16" WidthRequest="320">
<StackLayout>
<Label Text="No store information found!" FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center"/>
<Label Text="Please insert this information about your store" FontSize="Body" HorizontalOptions="Center" VerticalOptions="Center"/>
</StackLayout>
<StackLayout>
<Label Text="{Binding CountryTextBlockText}"/>
<UserControl:TextBox Text="{Binding CountryTextBoxText}" />
</StackLayout>
<StackLayout>
<Label Text="{Binding StreetTextBlockText}"/>
<StackLayout Orientation="Horizontal">
<UserControl:TextBox Text="{Binding StreetTextBoxText}" />
<UserControl:TextBox Text="{Binding HouseNumberTextBoxText}"/>
</StackLayout>
</StackLayout>
<StackLayout>
<Label Text="{Binding PostalCodeTextBlock}"/>
<UserControl:TextBox Placeholder="{Binding PostalCodeTextBoxText}" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding MapVisibilityLabel}"/>
<Switch IsToggled="{Binding ShowMapToggleToggled}"/>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding UseCurrentPositionButton}"/>
<Button Text="{Binding UseCurrentPositionButtonText}" Command="{Binding GetCurrentPositionButtonCommand}"/>
</StackLayout>
<map:Map HeightRequest="240" IsVisible="{Binding ShowMapToggleToggled}"/>
<Button Text="Submit" Command="{Binding SubmitButtonCommand}"/>
</StackLayout>
</ScrollView>
</Grid>
`
For UWP I created a Custom Renderer:
`
using Retailer.UWP.Renderer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
[assembly: ExportRenderer(typeof(Retailer.CustomControl.TextBox), typeof(TextBoxRenderer))]
namespace Retailer.UWP.Renderer
{
public class TextBoxRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
Control.BorderBrush = new SolidColorBrush();
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (((Retailer.CustomControl.TextBox)sender).BorderVisibility == false)
{
Control.BorderBrush = new SolidColorBrush();
}
if(e.PropertyName == nameof(TextBox.TextProperty))
{
if(Control.Text != (sender as Retailer.CustomControl.TextBox).Text)
Control.Text = (sender as Retailer.CustomControl.TextBox).Text;
}
}
private void FixFormsBackgroundColor(Xamarin.Forms.Frame frame)
{
var color = new Windows.UI.Color
{
A = Convert.ToByte(frame.BackgroundColor.A * 255),
R = Convert.ToByte(frame.BackgroundColor.R * 255),
G = Convert.ToByte(frame.BackgroundColor.G * 255),
B = Convert.ToByte(frame.BackgroundColor.B * 255)
};
if (Control.Parent is Panel parent)
{
parent.Background = null;
}
Control.Background = new SolidColorBrush(color);
}
}
}
`
For iOS:
`
using Retailer.CustomControl;
using Retailer.iOS.Renderer;
using System.ComponentModel;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(TextBox), typeof(TextFieldRenderer))]
namespace Retailer.iOS.Renderer
{
public class TextFieldRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Control == null)
{
Control.BorderStyle = UITextBorderStyle.None;
Control.BackgroundColor = UIColor.White;
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (Control != null && ((Retailer.CustomControl.TextBox)sender).BorderVisibility == false)
{
Control.BorderStyle = UITextBorderStyle.None;
}
else
{
Control.BorderStyle = UITextBorderStyle.Line;
}
}
}
}
`
And Android:
`
using Android.Content;
using Retailer.Droid.Renderer;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Retailer.CustomControl.TextBox), typeof(CustomEntryRenderer))]
namespace Retailer.Droid.Renderer
{
public class CustomEntryRenderer : EntryRenderer
{
public CustomEntryRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.SetBackground(new Android.Graphics.Drawables.ColorDrawable(Android.Graphics.Color.White));
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (((Retailer.CustomControl.TextBox)sender).BorderVisibility == false)
{
}
}
}
}
`
Changing the Properties in Constructure in ViewModel works to change the Value of myCustom Renderer TextBox. But I am trying to fill the TextBoxes with Lication Data from Geocoding.
` private string countryTextBoxText;
public string CountryTextBoxText
{
get { return countryTextBoxText; }
set { SetProperty(ref countryTextBoxText, value);
}
`
`
private async Task setCurrentPlacemark()
{
var location = await Geolocation.GetLocationAsync();
var placemarks = await Geocoding.GetPlacemarksAsync(location);
currentPlacemark = placemarks?.FirstOrDefault();
CountryTextBoxText = currentPlacemark.CountryName;
if (placemarks != null)
{
PositionDataDownloaded();
}
}
`
But this does not work. Replacing TextBox with Entry works perfectly. I think my Custom renderer does sot support Binding the original Text Property. But Why?
Hopefully someone can help.
How share image for instagram, facebook?
How share image for instagram, facebook?
searchable picker xamarin forms
can anyone suggest for searchable picker
Media Manager, correct usage?
Hi, I'm looking at using something I can use to play music and sound effects. I've come across the Media Manager and read a few things about it, but I cannot get it to play my audio file. I dunno if I am using the wrong code or my file directory for Android isn't correct. I have XAML calling an image from the same location and there are no compilation errors that it can't find the file.
I've also tried using the same play call in the button events but they are also unresponsive to play the audio. Though I can get it to crash by having it do an await on CrossMediaManager.Current.Play("ZeldaTheme.mp3"); in one of my button calls.