Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 91519 articles
Browse latest View live

Xamarin Forms TabbedPage question

$
0
0

Hello everybody,

I was tinkering around with the TabbedPage (regarding to https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/android/tabbedpage-toolbar-placement-color) but I have several problems.

On the xaml View I do not have the option to set
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.BarItemColor="Black"
android:TabbedPage.BarSelectedItemColor="Red"
while I can set them in the Code behind

My Visual Studio tells me that this Property can not be found. Instead I have only the choose between
android:TabbedPage.IsSmoothScrollEnabled
android:TabbedPage.IsSwipePagingEnabled
android:TabbedPage.OffscreenPageLimit

Also when I debug with the Android emulated device the


are not shown side by side, only one of them and the other two are invisible.

I am using Xamarin.Forms 3.6.0.264807 within a .net standard project.

What am I doing wrong or what am I missing?

Yours


SQLite Updates are 10 times slower on Android than iOS

$
0
0

Being somewhat new to SQLite and Xamarin I am not sure of why two different platform have two drastically different performances. In our app when a user logs in for the first time we need to sync a potentially large amount of data. To help with this we paralleled the sync process using asynchronous tasks (Task.WaitAll). We wrap these Wait All methods in a transaction and use a single connection through a data access layer. In iOS the whole process takes less than 2 seconds but in Android it takes between 20 - 30 seconds.

Has anyone had any issues like this using the SQLite.Net library? Is there any specific flags I need to set for Android?

If I try to use async transaction for each of the specific sync types that are being run in parallel then I get a SQLiteException: Busy error.

Reference Error in globalization

$
0
0

Hello all

Please can anyone help me?

When I am trying to globalize my texts using this XAML code:

xmlns:translate="clr-namespace:MeatStore.Supports;assembly=LocalizationSample"

 x:Class="MeatStore.Views.Onboarding">

        <StackLayout>

                <Label Text="{translate:Translate MeatSore}" />

        </StackLayout>

</ContentPage>

Error apears:

Severity Code Description Project File Line Suppression State
Error XLS0414 The type 'translate:Translate' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies >have been built. MeatStore.Android Onboarding.xaml 11

and

Failed to resolve assembly: 'LocalizationSample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' MeatStore.UWP

I am using Xamarin.form Shared Project in VS Enterprize

What is wrong with my code?

iOS: Expanding/contracting a native widget

$
0
0

I have written a custom control to wrap the UIDatePicker control as one entry in a form. The entry is initially contracted and the user can then tap it to expand the date/time picker. The expansion is animated.

This all works but doesn't perform very well on older iPhone models (iPhone 6 or older). I understand the UIDatePicker is quite heavy to render but would it make sense to write some custom view/renderer to contain it and perform the expand/contract animation at the iOS layer, rather than relying on the Xamarin.Forms animation API? Would it make any difference?

If so, can someone give me a hint as to how I control the bounds of a custom renderer? Just setting the bounds and calling the native view's SetNeedsLayout() doesn't affect the layout at all. How is Xamarin Forms layout engine interacting with custom renderers, as those have their bounds changed?

Binding style to content view not changing dynamicaly

$
0
0

I've two Frames with bound style properties and for each a tap event to change the actual content view:

<Frame Style="{Binding frameStyle1}"> ... <Frame.GestureRecognizers> <TapGestureRecognizer Tapped="FocusView1" NumberOfTapsRequired="1" /> </Frame.GestureRecognizers> </Frame> <Frame Style="{Binding frameStyle2}"> ... <Frame.GestureRecognizers> <TapGestureRecognizer Tapped="FocusView2" NumberOfTapsRequired="1" /> </Frame.GestureRecognizers> </Frame>

In the code behind I have this implementation of the properties and event handlers:

`public ContentView activeView {
get { return _activeView; }
set { if(_activeView != value) {
_activeView = value;
OnPropertyChanged("activeView"); }
}
}
public Style frameStyle1 {
get {
return (Style)(activeView == view1 ? App.Current.Resources["activeFrameStyle"] : App.Current.Resources["frameStyle"]);
}
}
public Style frameStyle2 {
get {
return (Style)(activeView == _view2 ? App.Current.Resources["activeFrameStyle"] : App.Current.Resources["frameStyle"]);
}
}
void FocusView1(object sender, EventArgs e) {
activeView = _view1;
}

void FocusView2(object sender, EventArgs e) {
activeView = _view2;
}`

My intention is to change style of all frames based on the current active view. On the application load the styles are set correctly but they are not updated when changing the active view.

Thanks for any help in advance...

Dependency Service Objects

$
0
0

Hi all,
I have a Interface like below

public interface ICalculator
{
        void setNum(int num);

        void getWidth();
}

and i implemented a class in Xamarin.Android using that interface like below

[assembly: Xamarin.Forms.Dependency(typeof(Calculator))]namespace Test.Droid
{
    class Calculator: IClaclulator
    {
        private int base = 0;

        public void setNum(int num)
        {
            base = num;
        }

        public int getBase()
        {
            return base;
        }
    }
}

but when i load this class in MainPage with DependencyService like this code

public partial class MainPage  ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        ICalculator icalculator = DependencyService.Get<ICalculator>(DependencyFetchTarget.GlobalInstance);
        icalculator.setNum(10);
        int result = icalculator.getBase();
    }
}

The result should be 10, but it seems that after setNum(10) the num variable in Calculator class will update but after calling getBase() num variable in class is not in memory and it will return default value which is 0;

How can i convert decimal value to text?

$
0
0

I try to create a table of item
public int Id { get; set; }
public string item_name { get; set; }
public decimal item_price { get; set; }
public decimal item_discount { get; set; }
public decimal quantity { get; set; }
public decimal total_amount { get; set; }

from the entry text how can i get the value of total_amount =(item_price*(item_discount/100 )) *quantity ;

Unable to Change Editor View for Compiler Directives

$
0
0

I am attempting to write Android and iOS specific code with compiler directives using an #ifdef block. I am however unable to change the editor of the preprocessor, there is no option for Android or iOS. All of my Android and iOS code therefore is in grey.


CameraController.ApplyCameraSettings System.NullReferenceException

$
0
0

while opening zxing scanner page app crashed :

CameraController.ApplyCameraSettings
android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object

Xamarin caused by: android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
ZXing.Mobile.CameraAccess.CameraController.ApplyCameraSettings()<57b37b10a314448c8d6b2b9155539100>:0
ZXing.Mobile.CameraAccess.CameraController.RefreshCamera()<57b37b10a314448c8d6b2b9155539100>:0
ZXing.Mobile.CameraAccess.CameraAnalyzer.RefreshCamera()<57b37b10a314448c8d6b2b9155539100>:0
ZXing.Mobile.ZXingSurfaceView.<SurfaceChanged>d__5.MoveNext()<57b37b10a314448c8d6b2b9155539100>:0
Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0()<2307420e33a04321993781fdb887a40e>:0
Java.Lang.Thread.RunnableImplementor.Run()<2307420e33a04321993781fdb887a40e>:0
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)<2307420e33a04321993781fdb887a40e>:0
at (wrapper dynamic-method) System.Object:b5211777-9dd6-4922-9884-a00186ce32e8 (intptr,intptr)
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:30
android.os.Handler.handleCallback()Handler.java:739
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:135
android.app.ActivityThread.main()ActivityThread.java:5276
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke()Method.java:372
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:911
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:706

how to solve this?

System.Resources.MissingManifestResourceException

$
0
0

Hello all

I am new to xamarin and I get this exception when I'm trying to globalize my project by using different language:

System.Resources.MissingManifestResourceException
HResult=0x80131532
Message=Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MeatStore.Resources.AppResources.resources" was correctly embedded or linked into assembly "MeatStore.UWP" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Source=System.Private.CoreLib

Sample of my project:
https://tltechsa-my.sharepoint.com/:f:/g/personal/hadi_ltechpro_com/EoJD1_pfPJxNi8izySN9mPkBOfFYXK1b0kMKRYtJw0JPwQ?e=t6Zaqs

Please anyone can help me?

Animation not working when HeightRequest is -1 for StackLayout. Bug?

$
0
0

When not setting a StackLayout Height size it is (-1). I want to hide this layout with an EventTrigger and a smooth animation ( 5 seconds ). This does not work. If I use a defined value height of 275, this does work.

I have also created a repo to demonstrate this issue. Has anyone found a work around for this?

System.NullReferenceException: Object reference not set to an instance of an object

$
0
0

im using App Center to collect insights about the app. im not using MainPage as my entry page.
In recieving this error

PageUtilities.GetCurrentPage (Xamarin.Forms.Page mainPage)
System.NullReferenceException: Object reference not set to an instance of an object
1
PageUtilities.GetCurrentPage (Xamarin.Forms.Page mainPage)
2
PrismApplicationBase.OnSleep ()
3
Application.SendSleepAsync ()
4
FormsAppCompatActivity+d__32.MoveNext ()
5
ExceptionDispatchInfo.Throw ()
6
TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
7
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
8
TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
9
TaskAwaiter.GetResult ()
10
FormsAppCompatActivity+d__28.MoveNext ()
11
ExceptionDispatchInfo.Throw ()
12
AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state)
13
SyncContext+<>c__DisplayClass2_0.b__0 ()
14
Thread+RunnableImplementor.Run ()
15
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
16
(wrapper dynamic-method) System.Object:1ccf4a28-d5de-41dd-ad05-219c61425ae0 (intptr,intptr)

how to pop an application to root view

$
0
0

Hi

I would like to have my Application show in the root view after it has been in the background for more than 5 min.
the following code gets called but nothing happens in the UI.

 public class App : Application
    {
        public static App Instance;
        private HomeView _HomePage;
        private DateTimeOffset _TimeWentToBack;
        public App(AppSetup setup)
        {
            Instance = this;
            _HomePage = AppContainer.Container.Resolve<HomeView>();

            MainPage = new CustomNavigationPage(_HomePage.GetMainPage())
            {
            };
        }

        public async void ClearNavigationAndGoToOverviewPageAsync()
        {
            var nav = MainPage.Navigation;
            await nav.PopToRootAsync();

        }

        protected override void OnStart()
        {
        }

        protected override void OnSleep()
        {
            _TimeWentToBack = DateTimeOffset.Now;
        }

        protected override void OnResume()
        {
            base.OnResume();
            TimeSpan timeSinceLastOpen = DateTimeOffset.Now - _TimeWentToBack;
            if (timeSinceLastOpen.TotalMinutes >= 5)
            {
                ClearNavigationAndGoToOverviewPageAsync();
                _HomePage.ReloadData();
            }
        }
    }

Thanks HP

InvalidOperationException when using PushAsync

$
0
0

Hi,

I am using Syncfusion TabView on my MainPage.

in my App starting the page like this:

MainPage = new NavigationPage(new MainPage());

then from the MainPage I am opening Signin as Popup like this:

Navigation.PushModalAsync(new Signin());

Until here all ok...

However, on the Sign in page I have a button to go to Sign up and I am trying to open the Sign up like this:

Navigation.PushAsync(new NavigationPage(new Signup()));

or like this:

Navigation.PushModalAsync(new Signup());

but keep getting this error:

Unhandled Exception:

System.InvalidOperationException: occurred

How to show the day of the week in datepicker for iOS?

$
0
0

I need to show the day of the week on the side of the day in datepicker for iOS, but i didn't find anything to do this.


How to use a Merged Resource Dictionary with android XML?

$
0
0

I'm using an xml file with android to define the style of a button. However when it comes to defining a color I'm not sure how I can access the merged dictionary from it. At the moment I'm using <solid android:color="@android:color/darker_gray"/> so how do I replace that with a reference to this... <Color x:Key="Gray">#777777</Color>

Photo Overlay for iOS using the Media Plugin

$
0
0

I am having difficulty implementing the Photo Overlay for iOS using the Media Plugin. I am trying to use Dependency Services to pass the function to the shared code, but have not succeeded. I am really stuck on how to implement the Dependency Service correctly.

My interface:
namespace TruFit
`{
public interface IPhotoOverlay
{
//Func Overlay = CreateOverlay;
object GetImageOverlayAsync();
//Func GetImageOverlayAsync();

    //Task<Stream> GetImageOverlayAsync();
}

}`

iOS code:
` public object GetImageOverlayAsync()
{
Func func = CreateOverlay;

        return func;
    }

    public object CreateOverlay()
    {
        var imageView = new UIImageView(UIImage.FromBundle("face-template.png"));
        imageView.ContentMode = UIViewContentMode.ScaleAspectFit;

        var screen = UIScreen.MainScreen.Bounds;
        imageView.Frame = screen;

        return imageView;
    }`

My shared code:
var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions() { //OverlayViewProvider = DependencyService.Get<IPhotoOverlay>().GetImageOverlayAsync, DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front});

How to change the position or size of a view in Relative Layout at runtime in xamarin.forms

$
0
0

What I did is I have added a label to a relative layout by setting all constraint.

Below is my code for that.

` relativeLayout.Children.Add(textLabel, Constraint.RelativeToView(innerBorderBox, (parent, sibling) =>
{
return sibling.Width * 0.55;
}), Constraint.RelativeToView(innerBorderBox, (parent, sibling) =>
{
return sibling.Y;
}), Constraint.RelativeToView(innerBorderBox, (parent, sibling) =>
{
return sibling.Width * .45;
}), Constraint.RelativeToView(innerBorderBox, (parent, sibling) =>
{
return sibling.Height;
}));

`
and it working perfectly.

Now I want to change that label(textLabel) X Constraint and Width Constraint dynamically. For example, from the above code X Constraint is sibling.Width * 0.55 and width is sibling.Width * .45, then need to change to X as sibling.Width * 0.55 + 10 and width is sibling.Width * .45 - 50. How to do that?

My guess is that it can be done by removing the label for the relative Layout and added again to relative layout with new constraint. But I think there will be a better solution for this.

How to change the position or size of a view in Relative Layout at runtime in xamarin.forms

$
0
0

What I did is I have added a label to a relative layout by setting all constraint.

Below is my code for that.

relativeLayout.Children.Add(textLabel, Constraint.RelativeToView(innerBorderBox, (parent, sibling) => { return sibling.Width * 0.55; }), Constraint.RelativeToView(innerBorderBox, (parent, sibling) => { return sibling.Y; }), Constraint.RelativeToView(innerBorderBox, (parent, sibling) => { return sibling.Width * .45; }), Constraint.RelativeToView(innerBorderBox, (parent, sibling) => { return sibling.Height; }));

and it working perfectly.

Now I want to change that label(textLabel) X Constraint and Width Constraint dynamically. For example, from the above code X Constraint is sibling.Width * 0.55 and width is sibling.Width * .45, then need to change to X as sibling.Width * 0.55 + 10 and width is sibling.Width * .45 - 50. How to do that?

My guess is that it can be done by removing the label for the relative Layout and added again to relative layout with new constraint. But I think there will be a better solution for this.

Xamarin and SignalR cannot connect

$
0
0

Hello Everyone,

I'm having a strange issue with Xamarin, I am trying to connect it to my SignalR Server hosted in Azure however when I call StartAsync() on my connection it seems to just hang - I don't get any errors or crashes. Does anyone know why Its doing thi?

My Code:
`connection = new HubConnectionBuilder()
.WithUrl("MYURL", options =>
{
options.AccessTokenProvider = () => Task.FromResult("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjcxZjE4YWFkLWM1NmItNDU3Yi05NzE5LWY2ZDg0YmRjMjdjYiIsIm5iZiI6MTU0NzgyMzEyMSwiZXhwIjoxNTUzMDA3MTIxLCJpYXQiOjE1NDc4MjMxMjF9.QMKN2kn0Rqvnt7lGaZAu1rSgncuLdOy7ioEArQa-FZw");
})
.Build();

try
{
await connection.StartAsync(); <-- This is where the code gets to then hangs.
}
catch (Exception ex)
{
throw ex;
}`

I have tried break pointing through the program and it always hits StartAsync() and then just hangs.

Any help would be appreciated!

Thanks,
Joe

Viewing all 91519 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>