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

Swap ContentView using MVVM

$
0
0

So what I first thought was a simple task, seems to be pretty complicated.
What I'm trying to accomplise is having a main page with a ContentView in the middle and a footer navigation bar.

The footer are in place, but I don't know how to put something in the content view and how to bind it to the buttons?

What should I bind what should I write in the MainViewModel?

MainPage:

<AbsoluteLayout>
        <StackLayout BackgroundColor="#ffffff" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All">
            <StackLayout Margin="0,200,0,0" HorizontalOptions="Center">
                <ContentView x:Name="MainPageContainer" 
                         HorizontalOptions="FillAndExpand" 
                         VerticalOptions="FillAndExpand" 
                         AbsoluteLayout.LayoutBounds="0.5, 0.5, 1, 1"
                         AbsoluteLayout.LayoutFlags="All" />
            </StackLayout>
        </StackLayout>
        <StackLayout AbsoluteLayout.LayoutBounds=".20,1.01,1,.1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="#f6f6f6" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
            <StackLayout Style="{StaticResource ButtonNavigationBarStackLayoutStyle}" x:Name="stckHome">
                <Image Source="{Binding HomeIcon}" Margin="0,15,0,15" x:Name="imgHome" Style="{StaticResource ButtonNavigationBarImageStyle}" />
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding TapHomeCommand}" NumberOfTapsRequired="1"></TapGestureRecognizer>
                </StackLayout.GestureRecognizers>
            </StackLayout>
            <StackLayout Style="{StaticResource ButtonNavigationBarStackLayoutStyle}" x:Name="stckSearch">
                <Image Source="{Binding SearchIcon}" Margin="0,15,0,15" x:Name="imgSearch" Style="{StaticResource ButtonNavigationBarImageStyle}" />
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding TapSearchCommand}" NumberOfTapsRequired="1"></TapGestureRecognizer>
                </StackLayout.GestureRecognizers>
            </StackLayout>
            <StackLayout Style="{StaticResource ButtonNavigationBarStackLayoutStyle}" x:Name="stckCreate">
                <Image Source="create.png" Margin="0,5,0,5" x:Name="imgCreate" Style="{StaticResource ButtonNavigationBarCreateImageStyle}" />
            </StackLayout>
            <StackLayout Style="{StaticResource ButtonNavigationBarStackLayoutStyle}" x:Name="stckFavorites">
                <Image Source="{Binding FavoritesIcon}" Margin="0,15,0,15" x:Name="imgFavorites" Style="{StaticResource ButtonNavigationBarImageStyle}" />
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding TapFavoritesCommand}" NumberOfTapsRequired="1"></TapGestureRecognizer>
                </StackLayout.GestureRecognizers>
            </StackLayout>
            <StackLayout Style="{StaticResource ButtonNavigationBarStackLayoutStyle}" x:Name="stckSettings">
                <Image Source="{Binding SettingsIcon}" Margin="0,15,0,15" x:Name="imgSettings" Style="{StaticResource ButtonNavigationBarImageStyle}" />
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding TapSettingsCommand}" NumberOfTapsRequired="1"></TapGestureRecognizer>
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </StackLayout>
    </AbsoluteLayout>


Background Colour Change Performance Terrible

$
0
0

I have created a custom control for a button that changes background colour to show whether it has been selected. However the colour change happens up to 5 seconds after the button press. Am i doing something wrong?

public class ToggleButton : Button
{
TextColor = Color.White;
BackgroundColor = Color.Black;
BorderColor = Color.White;
BorderWidth = 1;
CornerRadius = 4;

Clicked +=  (sender, e) =>
        {
            if (!IsEnabled)
                return;

            if (Command == null || !Command.CanExecute(CommandParameter))
                return;

            IsEnabled = false;
            IsToggled = !IsToggled;
            BackgroundColor = IsToggled ? Color.SteelBlue : Color.Black;

            //Command?.Execute(IsToggled);
            IsEnabled = true;
        };

}
If i debug the code,the breakpoint is hit immediately but it typically takes around 3 seconds to redraw the button.
I've commented out the command to eliminate it from any performance issues.

Thanks for any suggestions!
Andy

PS I am running this on the simulator until i can get back to the office next week

Link a library to my Solution - Failed to resolve assembly

$
0
0

Hey there.

I created a Solution and selected "Multiplatform -> Class Library". In it I created 2 Classes:

HslColorExtension.cs:

    using System;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;

    namespace Xamarin.FormsBook.Toolkit
    {
        public class HslColorExtension : IMarkupExtension
        {
            public HslColorExtension()
            {
                A = 1;
            }

            public double H { get; set; }
            public double S { get; set; }
            public double L { get; set; }
            public double A { get; set; }

            public object ProvideValue(IServiceProvider serviceProvider)
            {
                return Color.FromHsla(H, S, L, A);
            }
        }
    }

Toolkit.cs:

    using System;
    namespace Xamarin.FormsBook.Toolkit
    {
        public static class Toolkit
        {
            public static void Init()
            { }
        }
    }

Then I created another Solution but this time "Multiplatform -> Blank Forms App". I created a "Forms ContentPage XAML" and wrote this in there:

CustomExtensionDemoPage.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:toolkit="clr-namespace:Xamarin.FormsBook.Toolkit;assembly=Xamarin.FormsBook.Toolkit"
                 x:Class="BookCodedotNet2.CustomExtensionDemoPage">

        <StackLayout>
            <BoxView HorizontalOptions="Center"
                     VerticalOptions="CenterAndExpand">
                <BoxView.Color>
                    <toolkit:HslColorExtension H="0" S="1" L="0.5"/>
                </BoxView.Color>
            </BoxView>

            <BoxView HorizontalOptions="CenterAndExpand"
                     VerticalOptions="CenterAndExpand">
                <BoxView.Color>
                    <toolkit:HslColorExtension H="0.33" S="1" L="0.5"/>
                </BoxView.Color>
            </BoxView>

            <BoxView Color="{toolkit:HslColor H=0.67, S=1, L=0.5}"
                     HorizontalOptions="Center"
                     VerticalOptions="CenterAndExpand"/>

            <BoxView Color="{toolkit:HslColor H=0, S=0, L=0.5}"
                     HorizontalOptions="Center"
                     VerticalOptions="CenterAndExpand"/>

            <BoxView Color="{toolkit:HslColor H=0, S=0, L=1, A=0.5}"
                     HorizontalOptions="Center"
                     VerticalOptions="CenterAndExpand"/>

            <BoxView Color="{toolkit:HslColor H=0, S=0, L=0, A=0.5}"
                     HorizontalOptions="Center"
                     VerticalOptions="CenterAndExpand"/>
        </StackLayout>

    </ContentPage>

Then I added existing files to the project with "CustomExtensionDemoPage". I added a link to "HslColorExtension.cs" and "Toolkit.cs".

Then I changed App.xaml.cs so it looks like this

App.xaml.cs:

    using System;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;

    [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
    namespace BookCodedotNet2
    {
        public partial class App : Application
        {
            public App()
            {
                Xamarin.FormsBook.Toolkit.Toolkit.Init();


                InitializeComponent();

                 MainPage = new CustomExtensionDemoPage();
                //MainPage = new NavigationPage(new ResourceTreesPage());
            }

            protected override void OnStart()
            {
                // Handle when your app starts
            }

            protected override void OnSleep()
            {
                // Handle when your app sleeps
            }

            protected override void OnResume()
            {
                // Handle when your app resumes
            }
        }
    }

Now when Im trying to build my app I get this error:
/Users/username/Projects/BookCodedotNet2/BookCodedotNet2/CustomExtensionDemoPage.xaml: Error: Failed to resolve assembly: 'Xamarin.FormsBook.Toolkit, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' (BookCodedotNet2).

What did I do wrong? How do I fix it?

edit

I edited the References in my Project + .iOS + .Android. I added Xamarin.FormsBook.Toolkit in there. That way my Error Message changes to this:
/Users/username/Projects/BookCodedotNet2/BookCodedotNet2/CustomExtensionDemoPage.xaml(18,18): Error: Position 12:18. Type toolkit:HslColorExtension not found in xmlns clr-namespace:Xamarin.FormsBook.Toolkit;assembly=Xamarin.FormsBook.Toolkit (BookCodedotNet2)

Making use of the APK

$
0
0

Hi All,

Thanks again for all the past help... so now the app is built the icons are set... and the APK is made... (will be trying this for what seems to be a very complicated apple process very soon as I think I understand what xamarin is attempting... but to be honest... I will admit I don't understand the apple deployment process... we have a dev account but I am guessing I need to copy and paste my source code to visual studio on the mac?)

Any way this question is about installing the apk... currently two devices they I have tried here at the company to install the APK on the apk fails to install.
I am guessing I am not understanding the xamarin target framework option and the the min android version...

THe app is built with targeted frame work set at api 27... with the min android version at api 23 so and droid 8.1 thru 6.0....
I am guessing that the min android option is for show?

My users have android 8.0 on their devices so I thought that range would allow them to install and use the apk...

So far on the devices I have tried to install the apk on they have failed... the only device I can install the apk on is the android emulator I have on the development windows machine I made the application on...

When I selected adhoc on the archive from visual studio and gave it a signing password and all of that stuff...
but on the users devices the apk will not install..

Do I need to step down the target frame work and rewrite this basic app to work on each level of android so for example.. set target frame work and write a xamarin forms for that api level and step down and write on for android 6?

Will I need to do some similar for the apple products as well?

Thanks again guys

Xamarin Forms (Android) StartForegroundService not work (App crash)

Animations simply won't run with Samsung S7 Android 8.0

$
0
0

I'm having a weird issue with animations (such as TranslateTo method, any other anim method won't run also) in Xamarin Forms which makes every animated view to skip all the transitions and anim duration. The final result of my animations on this device is actually the view jumping/teleporting to its final destination in an instant (ignoring anim duration).

Decided to try the 'Easing' animation sample, but clicking 'run animation' button will simply teleport the image to the final position instantly.

To make sure this was related to this specific device, I tried the same sample (and other apps I built) with two other devices:

  • Motorola XT1040 Android 5.1
  • Samsung A5 2017 (SM-A520F) Android 8.0

Both could run the animations just fine.

I must add that I could run animations on my S7 before, but I lost track of when exactly it stopped working because I was working on other things that had no animations, so I can't precisely tell if it was some recent XF nuget update, firmware or even android API that caused this.

Also, no luck googling for similar cases, so I was left with the last choice of asking here for help.

Additional info about my phone:

  • Non-rooted
  • SM-G930F
  • Android 8.0

XForms version 3.4.0.1008975

Any help is appreciated. Thanks

How to add checkbox control in XAML

$
0
0

Hi,

I want to add Checkbox control in Xaml page. I added below code in .Xaml page.

    <CheckBox Margin="10, 10, 3, 3" 
                  Name="acceptPolicy" 
                  Content = "Accept our policy"
                  FontSize="12" 
                 Checked="CheckBox_Checked"/>

But i am getting below error?

Error CS0246: The type or namespace name 'CheckBox' could not be found (are you missing a using directive or an assembly reference?)

I am new to Xaml, since i am unable to find Checkbox control in Xamarin.Forms Xaml, i tried to use default Checkbox from here.

If some controls doesn't exist in Xamarin.Forms Xaml, whether can i use default Xaml controls or not?

Xamarin OneSignal API

$
0
0

Hello,
I created an xamarin app, android. I have enabled notifications, everything works.
The xamarin app only has a webview that opens up my MVC c# application, I need to send tags of users.
I tried with GONATIVE and with a simple javascript scripts I managed to do it.
How can i do this with xamarin?


Xamarin data transfer with Wi-Fi (HotSpot or Wi-Fi Driect)

$
0
0

I'm working on Arduino & Xamarin project. I want to data transfer with Wi-Fi. My codes ready Arduino side, but i don't find Xamarin Android source(Wi-Fi Source). I want to record a video with an Arduino camera and I want to send the video to an Android Phone via Wi-Fi connection.

ListView ItemSelected and ItemTapped not working with ContextActions

$
0
0

Hi all.
I have a problem with ListView. I have a viewcell with custom control that has TapGestureRecognizer and it works well. But when I added Context Action to ViewCell ItemSelected stoped working.
What can I do to solve this problem?
Thanks for helping.

How to display progress indicator while sound recording/playback takes place

$
0
0

I would like to display a progress indicator while recording sound in my app.
The amount of time allocated for the recording is predefined. I set that up in code, lets say 10 seconds maximum recording time.

I have been trying to make it work right could you please offer some guidance.
Note: I am using the NateRickard AudioRecorder nuget package.

(...)

        if (!recorder.IsRecording)
                {
                    buttonRecord.IsEnabled = false;
                    buttonPlay.IsEnabled = false;

                    DependencyService.Get<IAudioService>().PrepareRecording();

                    // start recording
                    var recordTask = await recorder.StartRecording();

                    buttonRecord.Text = "Stop Recording";
                    buttonRecord.IsEnabled = true;

                    // get the recorded file
                    var recordedAudioFile = await recordTask;

                    // set up progress bar
                    //progressBarRecordTime.Progress = 1.0;
                    //await progressBarRecordTime.ProgressTo(1.0, 10000, Easing.Linear);

                    buttonRecord.Text = "Record";
                    buttonPlay.IsEnabled = true;

                    if (recordedAudioFile != null)
                    {
                        var recordingFileDestinationPath = Path.Combine(FileSystem.AppDataDirectory, AppConstants.CUSTOM_ALERT_FILENAME);

                        if (File.Exists(recordingFileDestinationPath))
                        {
                            File.Delete(recordingFileDestinationPath);
                        }

                        File.Copy(recordedAudioFile, recordingFileDestinationPath);
                    }
                }

(...)

PayPal integration, xamarin forms shared project

$
0
0

Hi, I have a Xamarin forms shared project that has an Android and Windows phone project in it. I'm looking to integrate PayPal to simply make test sandbox payments, i.e. it wont be going live. This will be the first time I have attempted this, so I nothing of the process. Is there a plug in or package that I can add to my application?

also all and any How To's or guides would be greatly appreciated. I'm focused mostly on android integration with windows phone integration as a bonus.

Thanks in advance.

Error during release build

$
0
0

Unerwarteter Fehler bei der LinkAssemblies-Aufgabe.
Mono.Linker.MarkException: Error processing method: 'Android.Views.ScaleGestureDetector Xamarin.Forms.Platform.Android.GestureManager::InitializeScaleDetector()' in assembly: 'Xamarin.Forms.Platform.Android.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Android.Support.V4.View.ScaleGestureDetectorCompat::SetQuickScaleEnabled(Android.Views.ScaleGestureDetector,System.Boolean)
bei Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
bei Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
bei Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
bei Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
bei Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
bei Mono.Linker.Steps.MarkStep.ProcessQueue()
--- Ende der internen Ausnahmestapelüberwachung ---
bei Mono.Linker.Steps.MarkStep.ProcessQueue()
bei Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
bei Mono.Linker.Steps.MarkStep.Process()
bei MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
bei Mono.Linker.Pipeline.Process(LinkContext context)
bei MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
bei Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
bei Xamarin.Android.Tasks.LinkAssemblies.Execute()
bei Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
bei Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() Retailer.Android

Hello,
my code shows this error trying to build a release version.

Can someone explain me what
s happend?

Turn off control rendering in Previewer

$
0
0

We use Lottie animations and some other third part controls that Xamarin Forms Previewer doesn't understand so I get the "There was a problem rendering this document" error. Is there a keyword or something I can put in the control to tell the previewer to just ignore it? It would be nice if there was a flag such as Preview="false"

No resources found that matches at AndroidManifest.xml

$
0
0

Hello,

I am trying to follow this solution https://stackoverflow.com/questions/41524459/broadcast-receiver-not-working-after-device-reboot-in-android but I get the following error:
**
No resource found that matches the given name (at 'resource' with value '@xml/my_accessibility_service').**

with my_accessibility_service.xml :

<?xml version="1.0" encoding="utf-8" ?>
    <accessibility-service
      xmlns:android="http://schemas.android.com/apk/res/android"
        android:packageNames="myapp"
        android:accessibilityFeedbackType="feedbackSpoken"
        android:description="@string/service_desc"
        android:notificationTimeout="100">
    </accessibility-service>

Why is it happening?
Thanks


Picker popup is shown twice when calling focus()

$
0
0

Hello

I've an issue when a Picker (in my example an ExtendedPicker, but it also happens with a normal Picker). In some cases (see below), when calling Picker's focus() method, the popup opens twice in Android simulator (not sure about iOS/real device).

In my case I've got a ListView with a Picker on each item. They work as long as I don't delete an item. After I deleted an item, on some still existing items when opening Picker, it's opened twice.

To reproduce the problem, you can load the project from here: https://github.com/skurth/App1

1) Start app
2) Delete group "Tübach City" by pressing "Delete" button next to it.
3) Press on one of the three "Kopf" buttons from group "PSW Tübach" (not from group "1. FC Schwangere Bergente", there still one popup opens correctly). They open a picker.
4) Press OK on the opened Picker.
5) Another picker popup is shown. Why?

Is there something I do wrong or is it a bug?
Relevant code is in file "ItemCell.cs", starting from line 39.

(The reason why I set picker IsVisble=false and using a button instead of the standard picker label is because I need to customize font etc., and this way it's easier than writing a custom renderer for Picker.)

dependency service BroadcastReceiver send data back

$
0
0

hi,
what is the best way to send data back from the dependency service Broadcastreceiver (android) within the OnReceive method?
i used this project https://github.com/angelcalvasp/Blacksun.XamForms to build an dependency service for scanning BT devices. however, this project is not finished yet.

_bluetoothClient = DependencyService.Get();

public interface IBluetoothScanner
{
void StartDiscovery();

    void EndDiscovery();
}

public async Task SearchDevices()
{
_bluetoothClient.StartDiscovery();
await Task.Delay(TimeSpan.FromMilliseconds(10000));
_bluetoothClient.EndDiscovery();
}

public void StartDiscovery()
{
btAdapter.StartDiscovery();
}

    public void EndDiscovery()
    {
        btAdapter.CancelDiscovery();
    }

     broadcastReceiver = new CustomBroadcastReceiver();
            CurrentActivity = (Activity)Forms.Context;
            IntentFilter filter = new IntentFilter();
            filter.AddAction(BluetoothDevice.ActionFound);
            filter.AddAction(BluetoothAdapter.ActionDiscoveryStarted);
            filter.AddAction(BluetoothAdapter.ActionDiscoveryFinished);
            CurrentActivity.RegisterReceiver(broadcastReceiver, filter);

public class CustomBroadcastReceiver : BroadcastReceiver
{
public event EventHandler DeviceDiscoveryStarted;

    public event EventHandler DeviceDiscoverEnded;

    public event EventHandler<DeviceFoundEventArgs> DeviceDiscovered;

    public CustomBroadcastReceiver()
    {

    }

    public override void OnReceive(Context context, Intent intent)
    {

        String action = intent.Action;

        if (BluetoothAdapter.ActionDiscoveryStarted.Equals(action))
        {
            DoDeviceDiscoveryStarted();
        }
        else if (BluetoothAdapter.ActionDiscoveryFinished.Equals(action))
        {
            DoDeviceDiscoverEnded();
        }
        else if (BluetoothDevice.ActionFound.Equals(action))
        {

        //SEND DATA BACK TO FORMS
            System.Diagnostics.Debug.WriteLine("Found a device");
            BluetoothDevice device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice);
            //DoOnDeviceDiscovered(device.GetPairableBluetoothDevice());

        }
    }
}

thanks

Present UIImagePickerController from pagesheet modal jumps layout iOS 12

$
0
0

When present the iOS UIImagePickerController from an Pagesheet Modal in iOS 12, the modal jumps to the left top of the screen. When cancelling or taking a photo, the modal layout jumps back to it's original position. This problem started since iOS 12.

Does anyone have a fix for this problem? Or knows what this problem causes?

Before taking a photo:

When taking a photo (when UIImagePickerController showed):

What are the considerations to officially support webassembly/HTML5?

$
0
0

Considering the dawn of Xamarin Forms 4.X and the latest news on Connect() (open sourcing all relevant MS UI frameworks, but not accepting pull requests for any cross platform initiative) I think it's fair to ask these questions:

Are there any considerations to support webassembly/HTML5 as an official platform for Xamarin Forms?

  • If so, could you please elaborate on these considerations?
  • If no, could you please share the reasons which prevented MS from making XF available on webassembly/HTML5?

Note: I'm well aware of Ooui. However, with deep respect for the author and without any offense nor intention to discount his work I have to state:

  • there was not much activity on that project recently
  • after all that project is not 'backed up' by MS
    Hence, I could not consider it being at the same level as any potential, official support of Xamarin Forms for webassemblyHTML5

How to create shared frame layout to reuse it in other xaml pages!

$
0
0

I want to create a shared control to use this structure of frame inside my other xaml files:

<Frame
Padding="1"
BackgroundColor="Black
CornerRadius="7"
HasShadow="False">

                <Frame
                    Margin="2"
                    Padding="5"
                    BackgroundColor="White"
                    CornerRadius="5"
                    HasShadow="False">
    </Frame>

//My Other xaml control goes here.

</Frame

My doubt is how i can create this structure of frames in seperate xaml file to reuse it other xaml files!!

Viewing all 91519 articles
Browse latest View live


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