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

How to print an image using Bluetooth printer

$
0
0

I have spent many days to find an answer for this but still couldn't. I have a Xamarin cross platform app and what I need, is to print Barcode from a Bluetooth printer.

I used ZXing.Mobile to generate the barcode as a MemoryStream. It is a dependency injection and it works fine.
MemoryStream stream = new MemoryStream();
stream = (MemoryStream)DependencyService.Get().ConvertImageStream("C442871452");

Now I have a barcode image in Memory Stream. I have implemented another dependency service for printing. It can print text and work well.
await DependencyService.Get().Print("Text");

Now the question is how to print MemoryStream image?

I bought the Bluetooth printer from alibaba.com
https://www.alibaba.com/product-detail/Wireless-barcode-scanner-pos-printer-Black_60672727314.html?spm=a2700.galleryofferlist.normal_offer.d_image.4cd61b55PU0Ij9

Appreciate it if someone can share some codes.


CollectionView does not point to item details

$
0
0

I am using a CollectionView to display a list of multiple items. then I make an order when I click on an item it will lead to the item's detail page. but after I run this command it does not point to the item, but only opens the new item page. this is the command I made.

private async void KeEditSiswaa(object sender, SelectionChangedEventArgs e)
        {        
            if (e.CurrentSelection != null)
            {
                await Navigation.PushAsync(new EditSiswa
                {                  
                    BindingContext = e.CurrentSelection as Siswa
                });
            }
        }

PLEASE HELP: System.MissingMethodException

$
0
0

I upgraded my Xamarin packages to the latest version and all of the sudden my application won't even run. I get this error:

System.MissingMethodException: 'Method not found: bool Xamarin.Forms.Internals.ResourceLoader.get_IsEnabled()'

I really need a fix, or at least a way to revert my updates.

FlyoutHeader not showing in iOS after initialising a new instance of a shell

$
0
0

In our Xamarin Shell app, we have too shells. One is shown on load with a pre-login menu and a simple FlyoutHeader, then following a login process an instance of a new 'logged in' Shell with a different menu and FlyoutHeader are created and the user moved to that. (This shell is removed on logout and the user is returned to the first one).

The code for initialising the 'logged in' Shell is simply,

Shell s = new AppShellLoggedIn();
Application.Current.MainPage = s;

In both of the shell XAML files, the FlyoutHeader is included in the same way,

    <Shell.FlyoutHeader>
        <controls:FlyoutHeader />
    </Shell.FlyoutHeader>
    <Shell.FlyoutHeader>
        <controls:FlyoutHeaderLoggedIn />
    </Shell.FlyoutHeader>

This all works absolutely perfectly on android as you can see in the picture, and it works on iOS on the initial shell, but not the one that's created afterwards, the space where the header should be is simply empty. Duplicating the pre-login Header onto the logged in shell also leaves an empty space with no content.

(The text on the logged in header is dynamic and bound to the VM)

The FlyoutHeader controls are nothing particularly exciting, the pre-login one (that doesn't work if duplicated onto the logged-in one) is as below,

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:images="clr-namespace:Plugin.CrossPlatformTintedImage.Abstractions;assembly=Plugin.CrossPlatformTintedImage.Abstractions"
             x:Class="---" 
             x:Name="contentView" 
             HeightRequest="80">

    <StackLayout BackgroundColor="{DynamicResource FlyoutHeaderBackgroundColor}">

        <StackLayout x:Name="slNotLoggedIn">
            <Grid RowSpacing="0" ColumnSpacing="0" 
                  RowDefinitions="Auto, Auto, 2"
                  ColumnDefinitions="*, *">

                <images:TintedImage Source="logo"
                       HorizontalOptions="End"
                       VerticalOptions="Start"
                       WidthRequest="100"
                       Margin="25,30,30,10" Grid.Row="0" Grid.Column="1"
                       TintColor="{DynamicResource FlyoutLogoTint}"/>
            </Grid>

        </StackLayout>
    </StackLayout>
</ContentView>

Has anyone any suggestions as to what may be going wrong here?

Thanks

How to force registration for Remote Notifications using Azure Notification Hubs

$
0
0

Hello,

I built an app a while ago using Microsoft AppCenter for Remote Notifications. Now I need to switch to Azure Notification Hubs.
I'm using FirebaseMessagingService and in my tests everything went fine. But people who updated their app from the store don't receive Notifications.

I guess it is because OnNewtToken is never called, because they just updated the app (didn't reinstall it). On my phone it was called, because I reinstalled the app several times while testing.

My question is: how do I exactly force a Token Update/Registration?

The code so far:

`
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class FirebaseService : FirebaseMessagingService
{

public override void OnNewToken(string token)
{
Console.WriteLine("New Token");
SendRegistrationToServer(token);
}

    private void SendRegistrationToServer(string token)
    {
        Console.WriteLine("SendRegistrationToServer");
        try
        {
            NotificationHub hub = new NotificationHub(AppConfig.NotificationHubName, AppConfig.ListenConnectionString, this);
            Registration registration = hub.Register(token, AppConfig.SubscriptionTags);

            string pnsHandle = registration.PNSHandle;
            TemplateRegistration templateReg = hub.RegisterTemplate(pnsHandle, "defaultTemplate", AppConfig.FCMTemplateBody, AppConfig.SubscriptionTags);
            Console.WriteLine("Registered for notifications: " + templateReg.Tags);
        }
        catch (Exception e)
        {
            Log.Error(AppConfig.DebugTag, $"Error registering device: {e.Message}");
        }
    }

...
`

I thought I could put this code somewhere to force the update. But I don't know where:

var instanceId = await FirebaseInstanceId.Instance.GetInstanceId(); var token = instanceId.Class.GetMethod("getToken").Invoke(instanceId).ToString(); SendRegistrationToServer(token);

Any ideas? Thanks!

ContentPageBase - what the hell?

$
0
0

hello
Xamarin.Forms.V.2.4.0.282

I would like to add some controls to all of the content pages.
there for I have thought to make content page base.

so how to achieve that target? having a ContentPage_Base.
I have tried to follow a number of tutorials but all of them gives me error, syntax or compilation error...

thank you.

FreshMVVM Switching Navigation Stacks Between ContentPage and TabbedPage

$
0
0

I'm converting an app to use FreshMVVM from a non-MVVM format. When the app launches, there is a login page, then after login, a tabbed page with modal pages called from the buttons on each tabbed page.

Given the process I'm following, I figured that this would be a perfect option to use @MichaelRidland 's process to switch out NavigationStacks (github rid00z/FreshMvvm#switching-out-navigationstacks-on-the-xamarinforms-mainpage), but the steps appear to be missing quite a few important instructions, and these steps are not in the sample app on the GitHub.

In my App.xaml.xs file, I have the following code:

public App()
        {
            InitializeComponent();
            var loginPage = FreshMvvm.FreshPageModelResolver.ResolvePageModel<LoginPageModel>();
            var loginContainer = new STNavigationContainer(loginPage, NavigationContainerNames.AuthenticationContainer);
            var homePageViewContainer = new FreshTabbedNavigationContainer(NavigationContainerNames.MainContainer);

            MainPage = loginContainer;
        }

        public FreshTabbedNavigationContainer(string navigationServiceName)
        {
            NavigationServiceName = navigationServiceName;
            RegisterNavigation();
        }

        protected void RegisterNavigation()
        {
            FreshIOC.Container.Register<IFreshNavigationService>(this, NavigationServiceName)
        }

        public void SwitchOutRootNavigation(string navigationServiceName)
        {
            IFreshNavigationService rootNavigation =
                FreshIOC.Container.Resolve<IFreshNavigationService>(navigationServiceName);
        }
        public void LoadTabbedNav()
        {
            var tabbedNavigation = new FreshTabbedNavigationContainer();
            tabbedNavigation.AddTab<CharactersPageModel>("Characters", "characters.png");
            tabbedNavigation.AddTab<AdventuresPageModel>("Adventures", "adventures.png");
            tabbedNavigation.AddTab<AccountPageModel>("Account", "account.png");
            MainPage = tabbedNavigation;
        }
 public class NavigationContainerNames
    {
        public const string AuthenticationContainer = "AuthenticationContainer";
        public const string MainContainer = "MainContainer";
    }

I have extended the FreshNavigationContainter class and the FreshNavigationPage class. Here are my extended classes:

STNavigationContainer:

public class STNavigationContainer : FreshNavigationContainer
    {
        public STNavigationContainer(Page page) : base(page)
        {
        }

        public STNavigationContainer(Page page, string navigationPageName) : base(page, navigationPageName)
        {
        }

        protected override Page CreateContainerPage(Page page)
        {
            if (page is NavigationPage || page is MasterDetailPage || page is TabbedPage)
                return page;

            return new STNavigationPage(page);
        }
    }

STNavigationPage:

public class STNavigationPage : NavigationPage
    {
        public STNavigationPage()
        {

        }

        public STNavigationPage(Page page) : base(page)
        {
            BarBackgroundColor = Color.FromHex("#2DAFEB");
            BarTextColor = Color.FromHex("#C9371D");
        }
    }

This seems to match with the steps provided in the ReadMe.md, but the calls to NavigationServiceName return an error, since there's no instruction on creating such a class or what it should contain, nor am I clear on where the FreshTabbedNavigationContainer or SwitchOutRootNavigation would be called.

Has anyone been able to get this to work? What steps am I missing on this?

Inheritance from generic pages

$
0
0

Hello Xamarin Gurus,

I am doing a little experiment with inheritance and generics, here is the idea:
(I have a diagram to represent things more clearly, but I'm not authorised to post links yet)

The Models:

public interface IEntity { }

public abstract class Entity : IEntity
{
    public int Id { get; set; }
}

public class Instance : Entity
{
    public string Name { get; set; }
}

public class Volume : Entity
{
    public float VolumeValue { get; set; }
}

The ViewModels:

public interface IEntityViewModel<T> where T : IEntity { }

public abstract class EntityViewModel<T> : IEntityViewModel<T> where T : Entity
{
    public T Model { get; set; }
}

public class InstanceViewModel : EntityViewModel<Instance> { }

public class VolumeViewModel : EntityViewModel<Volume> { }

Now for the Views... this is where it gets complicated and broken.

EntityPage.xaml.cs:

public partial class EntityPage<T> : ContentPage where T : Entity
{
    public EntityPage(EntityViewModel<T> model)
    {
        InitializeComponent(); // error : method do not exist
        BindingContext = model;
    }
}

EntityPage.xaml:

<ContentPage x:Class="XamarinSample.View.EntityPage">
    <ContentPage.Content>
        <StackLayout >
            <Label Text="The Id is:"/>
            <Label Text="{Binding Model.Id}"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

VolumePage.xaml.cs:

public partial class VolumePage : EntityPage<Volume>
{
    public VolumePage(VolumeViewModel model) : base(model)
    {
        InitializeComponent();
    }
}

VolumePage.xaml:

<view:EntityPage x:TypeArguments="model:Volume" <!-- I specify the type of the generic type that EntityPage uses -->
    xmlns:view="clr-namespace:XamarinSample.View"
    xmlns:model="clr-namespace:XamarinSample.Model"
    x:Class="XamarinSample.View.VolumePage">
    <ContentPage.Content>
        <StackLayout >
            <Label Text="The VolumeValue is:"/>
            <Label Text="{Binding Model.VolumeValue}"/>
        </StackLayout>
    </ContentPage.Content>
</view:EntityPage>

The issue here is that I cannot call InitializeComponent() in the constructor of EntityPage because the generated code doesn't copy the genericity.

Generated code:

public partial class EntityPage : global::Xamarin.Forms.ContentPage {

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
    private void InitializeComponent() {
        global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(EntityPage));
    }
}

If I comment the problematic line and compile I get the following result from this quick&dirty initialisation:

        MainPage = new VolumePage(new ViewModel.VolumeViewModel()
        {
            Model = new Model.Volume() { Id = 50, VolumeValue = 500 }
        });

(still can't post links :neutral:)
The info about VolumeValue is displayed but not the info about the Id

Is there any way to make this work ? From the research I did prior to posting this, I would say it's not possible.

From your experience with Xamarin.Forms, would you say that it is better to use Composition over Inheritance to represent objects somewhat similar ? I am highly tempted to say yes.

Thanks in avance !


Odd Behavior now after no apparant changes.

$
0
0

Okay this one is really bizarre.
Suddenly my code is throwing some odd Java exceptions about not finding fonts, that I am not even using in my code. It's one of the Helvetica, and Sans Serif fonts, depending on what element it is crashing on.
I have fonts in my project, but neither of those fonts have ever been a part of my project.

Now it gets even better....
I tried updating all my NuGet packages, and saw that there had been an update to VS2019, so I updated that as well....
Now, I am getting some error saying expected enum but got (raw string) slide. in the values.xml file. This is an autogenerated file!? What is going on here!? I have a LOT of choice language I'd love to use, but will refrain as I'm trying to be professional and polite. But SERIOUSLY!
It's times like these I wish I had a cast iron skillet with me, so I could beat my head until it all made sense or didn't matter anymore.

If anyone has any ideas to try on EITHER of my issues, I'd desperately LOVE to hear them!

Thank you!

Tabbed pages are loading slowly

$
0
0

In my application, I used two tabbed pages...Whenever I triggered the tabbed page,it's taking too much time to open.and when I switched to another tab also it's taking time. My application performance became very slow due to these reasons.

Is there any solution to avoid these problems and to increase the performance of my application.

OnIdiom with AbsoluteLayout.LayoutBounds.

$
0
0

I have circular buttons and am trying to change the size of them depending on if they are on phone or tablet using absolute layout. Here is my code:

<Frame  BackgroundColor="{StaticResource ThemeColor}"
                Padding="0"
                CornerRadius="40"
                AbsoluteLayout.LayoutBounds="{StaticResource HomeCircle}"
                AbsoluteLayout.LayoutFlags="PositionProportional">
            <Label  Text="&#xf5a0;"
                        HorizontalOptions="Center"
                        VerticalOptions="Center"
                        Style="{StaticResource Icon}"
                        TextColor="{StaticResource LabelColor}"/>
            <Frame.GestureRecognizers>
                <TapGestureRecognizer Tapped="Directions"/>
            </Frame.GestureRecognizers>
        </Frame>
        <AbsoluteLayout.Resources>
            <ResourceDictionary>
                <OnIdiom x:Key="HomeCircle" x:TypeArguments="Frame" Phone=".85,.375, 80, 80" Tablet=".85,.375, 120, 120"/>
            </ResourceDictionary>
        </AbsoluteLayout.Resources>

I looked at this resource and it did not work:

https://stackoverflow.com/questions/40399224/how-to-use-attached-properties-such-as-grid-row-absolutelayout-layoutflags-to-o/40400273#40400273

Build issue After Migrating AndroidX ( Xamarin.Android.D8.targets)

$
0
0

I am facing an issue after migrating to AndroidX. That is Xamarin.Android.D8.targets(5,5): Error MSB6006: "java" exited with code 1.

any help is appreciated.

Draw table in PDF using skiasharp

$
0
0

Hello,

I am using skiasharp plugin to create pdf for android and ios both. I am able to create simple pdf provided in the sample but actually I want is table like structure inside pdf. I am not able to find how to insert table in skiasharp library.

I have done it before for android using iTextSharp plugin but this time I want to do it for iOS also. So finding cross-platform solution.

Anybody did that before ?

Thanks and Best Regards,
Sweets

Resetting MainPage

$
0
0

Hello.

Is the current Page object that is assigned to "MainPage" disposed if I set "MainPage" to a new Page object?

My concern is that multiple App.Current.MainPage = new PageXxx() will leave Page objects in memory, causing a leak.

Thanks in advance,

Mike

Clearing Webview cache

$
0
0

Is it possible to clear a webviews cache without deleting cookies? The sites js and css are getting updated often and need to make sure it is always loading the current version. Everything I have found seems to delete cookies, don't want to delete the cookies.


How to find the cause of: Xamarin.Forms targets have been imported multiple times

$
0
0

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?

change menu background color more

$
0
0

I have developed an application in xamarin forms, for other menu options there is a sub menu, but that menu in the dark theme is black, and I need it to be white, someone knows how to do it?

DisplayAlert crashing App

$
0
0

Hi,

I updated my Xamarin Forms from 4.8 to 5 and now DisplayAlert is crashing App when called on a phone running Android 5.1 so I had to downgrade to Xamarin Forms 4.8. And the DisplayAlert is working now. Even added Device.BeginInvokeOnMainThread

Device.BeginInvokeOnMainThread(async () =>
{

                var result = await DisplayAlert("Exit", "Are you sure you want to exit?", "Yes", "No");
                if (result)
                {
                    System.Diagnostics.Process.GetCurrentProcess().Kill();
                }
            });

Firebase Phone Authentication for Xamarin Forms

$
0
0

Firebase has made a solution for mobile phone authentication but there are no examples on how to implement it. I have managed to get email authentication working but nothing for Phone. I tried using the documentation for iOS and Android but I still cannot figure out how it should work.

https://firebase.google.com/docs/auth/android/phone-auth

This is what I'm trying to use for android. I made an interface in the shared folder, and a FirebaseAuthenticator in the android project, but the documentation for Android doesn't really help me. Does anyone have any idea or a working solution for Firebase.Auth for phone authentication?

How To Put User's Personal Information Into Firebase Realtime Database After Authentication?

$
0
0
I 'm authenticating the users with Firebase Authentication In Xamarin.Forms Project. Authentication is Successfull but I'm stuck at a point how to Put User's personal Data Such As Image, Name, Birth Etc To Firebase Realtime Database After the Authentication. AnyOne Can Help Me Regarding This Issue? Thanks
Viewing all 77050 articles
Browse latest View live


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