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

Label Line Breaks not working

$
0
0

I have a Xamarin Forms project with a very simple content page (code below). It's a stacklayout and I'm trying to use a simple LineBreakMode. But, it never seems to work. My long label text always gets cut off before the line break.

Note: I am using the Android Emulator to see the issue.

I did notice one weird thing (not sure if it's relevant). If I open Live Inspector and re-set the LineBreakMode, it works.

Anyone have any suggestions? I want to use the StackLayout and I have some pretty long labels that I want to wrap.

<ContentPage   
    xmlns:local="clr-namespace:SDPNativeClient.PagesTest"
    x:Class="SDPNativeClient.Pages.Test">
    <ScrollView Margin="20">
        <StackLayout>
            <Label Text="SDP Client sdgf dsgsd iljmsdiljm sdjsdjkldjs kljsdkljklsdjklsjklsdjkl jsdkldj klsdjsdgkljklsdjkljklsdj klsdj jklj kljkljklsj kljkljkljklsjkljsklgjsdklj klsdjklsdjsdkl " LineBreakMode="WordWrap" />    
        </StackLayout>
    </ScrollView>
</ContentPage>

Note: I took the xmlns to the xamarin schema out of the example code because the forum won't let me post links (even though it's not really a linnk) until I've been around a little longer :)


xamarin form ios not work background mode and kill app

$
0
0

Version Number of Plugin: 4.5.0.6 Device Tested On: Simulator Tested On:iphone x 11.4.1 Version of VS: 15.8.3 Version of Xamarin: Xamarin.Forms 3.1.0.697729 Xamarin.iOS and Xamarin.Mac SDK 11.14.0.13 (373c313)

I'm trying to make the position update work even when the app is in the backgorund, and even when it's closed. with android everything works fine. with ios it only works in the simulator, just test in a physical device, it does not work if I put the app in the background. just from the backgorund I go in foreground calls me different want the event of the change of position even if I set every 20 seconds, how could I do?

`public MasterViewModel()
{
ListMasterPageItem = ListMenuService.GetMenuItems();
if (Device.RuntimePlatform == Device.iOS)
{
StartListening();
}
}

async Task StartListening()
{

    if (CrossGeolocator.Current.IsListening)
        return;

    ///This logic will run on the background automatically on iOS, however for Android and UWP you must put logic in background services. Else if your app is killed the location updates will be killed.
    await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(20), 10, true, new ListenerSettings
    {
        ActivityType = ActivityType.Other,
        AllowBackgroundUpdates = true,
        DeferLocationUpdates = false,
        DeferralDistanceMeters = null,
        DeferralTime = null,//TimeSpan.FromSeconds(1),
        ListenForSignificantChanges = true,

        PauseLocationUpdatesAutomatically = false
    });

    CrossGeolocator.Current.PositionChanged += Current_PositionChanged;
}`

My Permission:
`NSLocationAlwaysUsageDescription
Can we use your location
NSLocationWhenInUseUsageDescription
We are using your location
NSLocationAlwaysAndWhenInUseUsageDescription
Can we use your position to send you targeted offers and find the different stores?
NSMicrophoneUsageDescription
Allows you to recognise your voice to create tasks
NSCalendarsUsageDescription
Some ad content may access calendar
NSContactsUsageDescription
This app requires contacts access to function properly.
NSAppleMusicUsageDescription
Play using while you are hiking
NSSiriUsageDescription
This app siri use.
UIBackgroundModes

location
remote-notification`

Xamarin forms Authentication how?

$
0
0

How do you people do authentication using google and facebook ? It seems to be very problematic and there is not easy way.
1) using web login (looks ugly but easiest way)
2) using native login (looks good, increases your app size and so much native programming)

which one is better out of these? microsoft claim, it is better to use web login as they provide for Azure Active Directory B2C
Which technology?
1) Xamarin Auth : full of open issues on their github. last time I tried UWP was failing.
2) Azure Mobile Services: this was the only working option for me last time I tried but I dont know after google changing their policy, how it works? because it was working based on webview and didnt didnt support native browser.
3) Azure Active Directory B2C: It looks like that it is the easiest solution but way toooooooooo expensive for poor developers.
5) Aspnet membership with custom web api. I achieved this very quick with own username password. very simple but external logins looks like impossible.
4) Others

Please share your thoughts and how you implemented?

I need a photo slideshow in various parts of my application. How can i create web like features UI?

$
0
0

One of the dominant forces for npm and all of the js out there are it's prebuilt items. If i needed a slideshow or scrolling banner how would i go about doing that in Xamarin.forms? Also, is there in general ui widgets or advanced touch functionality per se for the windows and ios platforms that xamarin taps into?

How to hide keyboard when focusing Entry

$
0
0

I have a Xamarin.forms project, I have a page with an Entry control, I want to hide the keyboard when the Entry gets the focus ,because it is for scanning barcode labels, how can I achieve that?
The following code can implement hidden keyboard, but the keyboard occasionally shows,especially when the entry is empty.
How can I avoid it?thanks
here is my caode :
Control.InputType = 0;
Control.ShowSoftInputOnFocus = false;
InputMethodManager inputMethodManager = Control.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
inputMethodManager?.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);

How to hide keyboard when focus Entry

$
0
0

I have a Xamarin.forms project, I have a page with an Entry control, I want to hide the keyboard when the Entry gets the focus ,because it is for scanning barcode labels, how can I achieve that?
The following code can implement hidden keyboard, but the keyboard occasionally shows,especially when the entry is empty.
How can I avoid it?thanks
here is my caode :
Control.InputType = 0;
Control.ShowSoftInputOnFocus = false;
InputMethodManager inputMethodManager = Control.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
inputMethodManager?.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);

How to hide keyboard when focus Entry

$
0
0

I have a Xamarin.forms project, I have a page with an Entry control, I want to hide the keyboard when the Entry gets the focus ,because it is for scanning barcode labels, how can I achieve that?
The following code can implement hidden keyboard, but the keyboard occasionally shows,especially when the entry is empty.
How can I avoid it?thanks
here is my caode :
Control.InputType = 0;
Control.ShowSoftInputOnFocus = false;
InputMethodManager inputMethodManager = Control.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
inputMethodManager?.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);

How to hide keyboard when focus Entry

$
0
0

I have a Xamarin.forms project, I have a page with an Entry control, I want to hide the keyboard when the Entry gets the focus ,because it is for scanning barcode labels, how can I achieve that?
The following code can implement hidden keyboard, but the keyboard occasionally shows,especially when the entry is empty.
How can I avoid it?thanks
here is my caode :
Control.InputType = 0;
Control.ShowSoftInputOnFocus = false;
InputMethodManager inputMethodManager = Control.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
inputMethodManager?.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);


Xamarin OCR

$
0
0

So far I tried out Tesseract and Microsoft Cognitive Service and I wish to ask is there any other OCR service and engine that is easy to implement and provide accurate result?

How to build a page like the overlay loading page

$
0
0

I want to build a page in xamarin forms like this and I need to replace the "Loading" with a content view which contains some buttons and sliders.
It should work in IOS, can anyone teach me this or give me some links about it?

Thank you very much

Image processing

$
0
0

Can anyone share code on image binarization and remove noise ?

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android

$
0
0

Hi Team,

In our Xamarin Forms application we are referring Xamarin forms version: 3.0.0.446417. With this version it is working fine. We have Login Page, Master Detail page we are using. Problem is when i upgraded Xamarin Forms version to latest stable version: 3.1.0.697729 application is crashing on Android device. In the Master Detail Page in the menu section on tapping of "Logout" option, Login Page is getting rendered partially and it is getting crashed. Below is the error i'm getting:

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0xbee1e730 (key_handle 0x7fe2fc7).

can any one help me in fixing this issue.

Regards,
Thejesh.

Custom renderer; replacing the native control properly

$
0
0

Let's say I want to use my custom Android button FlatButton from the FlatUI component on the store.

I can simply write a custom renderer like this:

    public class MyButtonRenderer : ButtonRenderer
    {

        private FlatButton _button;

        public MyButtonRenderer()
        {
            _button = new FlatButton (Forms.Context);
            _button.Theme = FlatTheme.Sky ();
        }

        protected override void OnElementChanged (ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged (e);
            SetNativeControl (_button);
        }
    }

However, there are problems:

  • It loses all even handlers like the click handler.
  • It behaves randomly sometimes, so within a ListView the text displayed will be in a wrong size, but scrolling up and down again makes it renders correctly.

I must be doing something wrong here or missing something, what is it?
Basically, what's the right way of setting my own native control using SetNativeControl without messing things up?

Can i code for a Xamarin.forms css style sheet base on platform? Can i target a style sheet?

$
0
0
  1. Is it possible to target an entire stylesheet base on platform for CSS?
  2. Is it possible to targe a specific style for a specific platform based on CSS?

How to round off the corners of a Button and a StackLayout

$
0
0

Hello,
I'm actually making an application on Xamarin. I have created a Stacklayout with buttons inside. How can I round off the corners ? I use BorderRadius for the button but it doesn't work.

Thank you :smile:


How to change BG color for ViewCell ContextActions

$
0
0

Hi guys,
Hope your doing great,
I created ListView with three Context Actions, here I want to set different background color for each MenuItem like below

<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="PureSale.Core.Views.OrdersListTemplate">
    <Grid Padding="10">
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <StackLayout Spacing="5">
           <Label Text="{Binding Title}" FontAttributes="Bold" HorizontalOptions="StartAndExpand"/>
         <Label Text="{Binding StartDate}" HorizontalOptions="StartAndExpand"/>
     </StackLayout>
        <Image Source="indicatorIconBlack.png" Grid.Column="1" HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand"/>
    </Grid>
</ViewCell>


public partial class OrdersListTemplate : ViewCell {
    public OrdersListTemplate(){
        InitializeComponent();

  var deleteAction = new MenuItem { Text = "Delete", StyleId = "labelRedStyle" };
        deleteAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
        deleteAction.Clicked += (sender, e) => {
        };

        var archiveAction = new MenuItem { Text = "Archive", IsDestructive = true}; 
        archiveAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
        archiveAction.Clicked +=  (sender, e) => {
        };

        var cancelAction = new MenuItem { Text = "Cancel" };
        cancelAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
        cancelAction.Clicked += (sender, e) => {
        };

    ContextActions.Add(cancelAction);
            ContextActions.Add(archiveAction);
            ContextActions.Add(deleteAction);
   }
}

XAML

<ListView HasUnevenRows="true" ItemsSource="{Binding OrderItems}" ios:ListView.SeparatorStyle="FullWidth" SelectedItem="{Binding SelectedListItem}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <views:PartyListTemplate/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

How can I set StyledId for menu item, Please suggest me
Thanks in advance

Xamarin.Forms Speech to Text crashes on iPad iOS

$
0
0

Hi,

I have an app developed in Xamarin.Forms. I Used SpeechToText functionality in the app. It works fine on Android and iPhone, but on iPad it failed with following run time exception on first or second tap:

Hardware Model: iPad4,8
OS Version: iPhone OS 10.2.1 (14D27)

```
Application Specific Information:
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'

    Last Exception Backtrace:
    0   CoreFoundation                       0x000000018cddd1b8 __exceptionPreprocess + 124
    1   libobjc.A.dylib                      0x000000018b81455c objc_exception_throw + 52
    2   CoreFoundation                       0x000000018cddd08c +[NSException raise:format:arguments:] + 100
    3   AVFAudio                             0x00000001a62a3300 AVAE_RaiseException(NSString*, ...) + 56
    4   AVFAudio                             0x00000001a6318abc AVAudioNodeImplBase::CreateRecordingTap(unsigned long, unsigned int, AVAudioFormat*, void (AVAudioPCMBuffer*, AVAudioTime*) block_pointer) + 268
    5   AVFAudio                             0x00000001a6316718 -[AVAudioNode installTapOnBus:bufferSize:format:block:] + 212
    6   AgriSynciOS                          0x00000001015d7588 wrapper_managed_to_native_ObjCRuntime_Messaging_objc_msgSend_intptr_intptr_System_nuint_uint_intptr_intptr (<unknown>:1)
    7   AgriSynciOS                          0x0000000101590788 AVFoundation_AVAudioNode_InstallTapOnBus_System_nuint_uint_AVFoundation_AVAudioFormat_AVFoundation_AVAudioNodeTapBlock (AVAudioNode.g.cs:118)

````
Below is the code (used with Dependencyservice):
` public class SpeechToTextImplementation : ISpeechToText
{
private Action _callback;

    #region Private Variables
    private AVAudioEngine AudioEngine;
    private SFSpeechRecognizer SpeechRecognizer;
    private SFSpeechAudioBufferRecognitionRequest LiveSpeechRequest;
    private SFSpeechRecognitionTask RecognitionTask;
    #endregion

    public SpeechToTextImplementation()
    {

    }

    public void InitializeProperties()
    {
        try
        {
            if (AudioEngine == null)
                AudioEngine = new AVAudioEngine();
            if (SpeechRecognizer == null)
                SpeechRecognizer = new SFSpeechRecognizer();
            if (LiveSpeechRequest == null)
                LiveSpeechRequest = new SFSpeechAudioBufferRecognitionRequest();
        }
        catch (Exception ex)
        {
            LogController.LogError(ex.Message, ex);
        }
    }

    public void Start(Action<EventArgsVoiceRecognition> handler)
    {
        _callback = handler;
        AskPermission();
    }

    public void Stop()
    {
        CancelRecording();
    }

    void AskPermission()
    {
        try
        {
            // Request user authorization
            SFSpeechRecognizer.RequestAuthorization((SFSpeechRecognizerAuthorizationStatus status) =>
            {
                // Take action based on status
                switch (status)
                {
                    case SFSpeechRecognizerAuthorizationStatus.Authorized:
                        InitializeProperties();
                        StartRecordingSession();
                        break;
                    case SFSpeechRecognizerAuthorizationStatus.Denied:
                        // User has declined speech recognition

                        break;
                    case SFSpeechRecognizerAuthorizationStatus.NotDetermined:
                        // Waiting on approval

                        break;
                    case SFSpeechRecognizerAuthorizationStatus.Restricted:
                        // The device is not permitted

                        break;
                }
            });
        }
        catch (Exception ex)
        {
            LogController.LogError("SpeechRecognition::AskPermission", ex);
        }
    }

    public void StartRecordingSession()
    {
        try
        {
    //var format = new AVAudioFormat(AVAudioCommonFormat.PCMInt16, 44100, 2, false);

            // Start recording
            AudioEngine.InputNode.InstallTapOnBus(
                bus: 0,
                bufferSize: 1024,
                format: AudioEngine.InputNode.GetBusOutputFormat(0),
                tapBlock: (buffer, when) => LiveSpeechRequest?.Append(buffer)); ///Throw exception from here. 

            AudioEngine.Prepare();
            NSError error;
            AudioEngine.StartAndReturnError(out error);
            //AudioEngine.MainMixerNode.
            // Did recording start?
            if (error != null)
            {
                return;
            }

            CheckAndStartReconition();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void CheckAndStartReconition()
    {
        if (RecognitionTask?.State == SFSpeechRecognitionTaskState.Running)
        {
            CancelRecording();
        }
        StartVoiceRecognition();
    }

    public void StartVoiceRecognition()
    {
        try
        {
            RecognitionTask = SpeechRecognizer.
                GetRecognitionTask(LiveSpeechRequest,
                (SFSpeechRecognitionResult result, NSError err) =>
            {
                try
                {
                    if (result == null)
                    {
                        CancelRecording();
                        return;
                    }
                    // Was there an error?
                    if (err != null)
                    {
                        CancelRecording();
                        return;
                    }
                    //   Is this the final translation?
                    if (result != null && result.BestTranscription != null && result.BestTranscription.FormattedString != null)
                    {
                        Console.WriteLine("You said \"{0}\".", result.BestTranscription.FormattedString);
                        TextChanged(result.BestTranscription.FormattedString);
                    }
                    if (result.Final)
                    {
                        TextChanged(result.BestTranscription.FormattedString, true);
                        CancelRecording();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    CancelRecording();
                }
            });
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void StopRecording()
    {
        try
        {
            AudioEngine?.Stop();
            LiveSpeechRequest?.EndAudio();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void CancelRecording()
    {
        try
        {
            AudioEngine?.Stop();
            RecognitionTask?.Cancel();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    public void TextChanged(string text, bool isFinal = false)
    {
        // textChanged?.Invoke(this, new EventArgsVoiceRecognition(text, isFinal));
        if (_callback != null)
            _callback(new EventArgsVoiceRecognition(text, true));
    }
}

`

Any thought on this?

LoginPage with FreshMVVM ?

$
0
0

Hello,

what is the best way to implement a Login page with FreshMVVM ?

Any sample or suggestion ?

Thank you

Marco

How to set custom font family using CSS in Xamarin ?

$
0
0

I'm trying to set custom font family using CSS file in Xamarin forms project. My custom font is 'Bodoni'.
I placed the respective font files in the android and ios project (MyApp.Mobile.App.Android/Assets/Bodoni.ttf for android) and (MyApp.Mobile.App.iOS/Resources/Bodoni.tff for IOS).
Those font files target its BuildAction as AndroidAsset for Android project and BundleResource for iOS project.

The CSS file is defined in the common project and declared in the App.xaml

.titleLabel {
font-family: Bodoni;
color: #960051;
}

The css file is well interpreted and my element (Label) contains the styleClass attribute with the 'titleLabel' value.
The color property works well but the font family does not change.

Are there any other manipulations to do to integrate my custom font ?

Note : When I try to target the the font files as AndroidResource, this error appear : invalid resource directory name: MyApp.Mobile.App.Android\obj\Debug\res assets "res assets".

Can you have a scrollview in a scrollview?

$
0
0

I have a carousel page that has 4 content pages. 2 of the pages require that i create a "lookup" entry box and brings up data as the user is typing. I'm doing this via a webservice call and populating the data into a grid thats visibility is controlled by a boolean.

What I need is the lookup grid to be in a scrollview with a fixed height so that i can scroll through the results. My issue is that all this content is already inside of a scrollview.

so I have something like this in a single content page. this one is kind of complicated.

<stacklayout> <grid/> <grid/> <scrollview> <stacklayout> <grid/> <grid> <scrollview> <Devexpress grid/> <scrollview/> <stacklayout/> <scrollview/> <grid/> <stacklayout/>

the devexpress grid displays and works the way i need it to but it will not scroll through its items.

Is this even possible?

Thanks in advance for any help!

Viewing all 77050 articles
Browse latest View live


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