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

Upper TabbedPage shadow border

$
0
0

Hi,

When using TabbedPage, I managed to add a shadow to the bottom border by setting the BackgroundColor to white. But how can I create a shadow border for the upper tabs? See picture below for clarification of what I am trying to do.

Thank you in advance!


How to get verticalOffset position after ScrollTo methods in collectionview?

$
0
0

I have a collectionview and want to get the verticalposition after scrollTo () .But the Scrolled only get the previous position not the right position.
how to do it?

AudioTrack couses short stops?

$
0
0

I have an app streaming music to another phone via Bluetooth. The app decodes mp3 to pcm data and then sends it. The problem is the sound stutters sometimes, but plays ok other times. The play method looks like this:

    public void Read()
    {
        System.Threading.Tasks.Task.Run(() =>
        {
            int _bufferSize;
            AudioTrack _output;

            _output = new AudioTrack(Android.Media.Stream.Music, 44100, ChannelOut.Stereo, Android.Media.Encoding.Pcm16bit,
                10000, AudioTrackMode.Stream);
            _output.Play();

            byte[] myReadBuffer = new byte[1000];
            //byte[] check = new byte[1];

            System.Threading.Tasks.Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        mmInStream.Read(myReadBuffer, 0, myReadBuffer.Length);
                        _output.Write(myReadBuffer, 0, myReadBuffer.Length);
                        //mmOutStream.Write(check);
                    }
                    catch (System.IO.IOException ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Input stream was disconnected", ex);
                    }
                }
            }).ConfigureAwait(false);
        }).ConfigureAwait(false);
    }

And after a while it stops and displays this:

    02-03 19:08:58.019 W/AudioTrack( 3986): releaseBuffer() track 0xc5e2de00 disabled due to previous underrun, restarting

How would I fix this?

ChatUI - move input Text above keyboard

$
0
0

Hi - i have been following this tutorial to create a Chat UI:
https://www.xamboy.com/2018/06/14/exploring-a-chat-ui-in-xamarin-forms-part-1/

This seems to work by adding a margin to the view which holds the textbox in the OnKeyboardAppearing method in the custom renderer - however - I have a Navigation Page inside a Tabbed Page and for this the input view gets raised too high..

I've subtracted the TabBar height but there is still gap there.. i've tried manually adding a number to reduce the margin, but then that only works on one version of iPhone because of the different dimensions..

any thoughts how to achieve this?

ChatSendRenderer

using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using Foundation;
using CoreGraphics;
using ChatUIXForms.iOS.Renderers;


[assembly: ExportRenderer(typeof(ChatSendView), typeof(ChatSendRenderer))]
namespace ChatUIXForms.iOS.Renderers
{
    public class ChatSendRenderer : ViewRenderer //Depending on your situation, you will need to inherit from a different renderer
    {
        NSObject _keyboardShowObserver;
        NSObject _keyboardHideObserver;
        protected override void OnElementChanged(ElementChangedEventArgs<View> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                RegisterForKeyboardNotifications();
            }

            if (e.OldElement != null)
            {
                UnregisterForKeyboardNotifications();
            }
        }

        void RegisterForKeyboardNotifications()
        {
            if (_keyboardShowObserver == null)
                _keyboardShowObserver = UIKeyboard.Notifications.ObserveWillShow(OnKeyboardShow);
            if (_keyboardHideObserver == null)
                _keyboardHideObserver = UIKeyboard.Notifications.ObserveWillHide(OnKeyboardHide);
        }

        void OnKeyboardShow(object sender, UIKeyboardEventArgs args)
        {

            NSValue result = (NSValue)args.Notification.UserInfo.ObjectForKey(new NSString(UIKeyboard.FrameEndUserInfoKey));
            CGSize keyboardSize = result.RectangleFValue.Size;
            if (Element != null)
            {


                Element.Margin = new Thickness(0, 0, 0, keyboardSize.Height - App.TabHeight); //push the entry up to keyboard height when keyboard is activated

            }
        }

        void OnKeyboardHide(object sender, UIKeyboardEventArgs args)
        {
            if (Element != null)
            {
                Element.Margin = new Thickness(0); //set the margins to zero when keyboard is dismissed
            }

        }


        void UnregisterForKeyboardNotifications()
        {
            if (_keyboardShowObserver != null)
            {
                _keyboardShowObserver.Dispose();
                _keyboardShowObserver = null;
            }

            if (_keyboardHideObserver != null)
            {
                _keyboardHideObserver.Dispose();
                _keyboardHideObserver = null;
            }
        }
    }
}

ChatPage

 <Grid RowSpacing="0" 
       ColumnSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="6" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="6" />
    </Grid.RowDefinitions>

      <controls:CustomListView Grid.Row="0" 
             ItemTemplate="{StaticResource MessageTemplateSelector}" 
             ItemsSource="{Binding Chats}" 
             Margin="0"
             ItemTapped="OnListTapped"
             HasUnevenRows="True" 
             VerticalOptions="FillAndExpand" 
             SeparatorColor="Transparent"
            x:Name="ChatList"

                >
     </controls:CustomListView>

      <BoxView HorizontalOptions="FillAndExpand"
             HeightRequest="6"
             BackgroundColor="#E5E5E5"
             Grid.Row="1"/>


      <ChatSendView Grid.Row="2"
                            Margin="0,0,0,0"
                            x:Name="chatInput"
                            />

      <BoxView HorizontalOptions="FillAndExpand"
             HeightRequest="6"
             BackgroundColor="#E5E5E5"
             Grid.Row="3"/>

</Grid>

ChatSendView

 <Grid RowSpacing="0" BackgroundColor="#E5E5E5"
       ColumnSpacing="0">
           <Grid.RowDefinitions>
                 <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

     <controls:ExtendedEditorControl x:Name="chatTextInput" 
             Text="{Binding TextToSend}" 
             Margin="10,0,10,0"  
             TextColor="Black" 
             Keyboard="Chat"
             IsExpandable="true"
             HorizontalOptions="FillAndExpand" 
             PlaceholderColor="LightGray"
             Placeholder="Type your message here"
             Grid.Row="0" 
             Grid.Column="0"
             />

     <Button Grid.Row="0"
           Grid.Column="1"
             Text="Send"
             Style="{StaticResource btn_primary}" WidthRequest="50" Margin="10,0,10,0"

             Clicked="Handle_Completed"
             ></Button>


</Grid>

Xamarin.Forms MicroCharts BarChart with Multiple Values

$
0
0

I'm using MicroCharts barChart:
I import everything.

I read a list of data from Api. I need to show the data grouped by parameter year(i read from every object from the list) and have 3 values for every year to show. Similar like this example:

Any suggestions?

Microsoft.AspNetCore.SignalR.Client, IOS device on released build

$
0
0

Hi,
I am using Microsoft.AspNetCore.SignalR.Client 3.0.0 nuget package (also tried the 3.1.1 version).
On android devices works properly on Debug and Released version.
On IOS devices works properly on Debug but not on Released version.
I would like to ask if there are any additional steps that i need to implement in order the IOS device use SignaR realtime connection on released version?
I can't figure it out why on Debug works but not on Released version.
Any help will be appreciated!
Regards.

Any chance to communicate WCF in Xamarin Forms?

$
0
0

I want to migrate from windows operating system to android system. What I cannot achieve from the beginning is established communication with WCF engine.

Currently, we are using WPF to established connection to WCF. Current code:-

Private Function EstablishConnect() As Boolean
    Try
        Dim context = New InstanceContext(Me)
        svrobj = New WCFEngine.EngineServices.DisplayServicesClient(context, "DisplayTcpBinding")
        Dim endpointAddress = New EndpointAddress(modUtility.ServerEndPointAddress)
        svrobj.Endpoint.Address = endpointAddress
        svrobj.Open()
        modUtility.SecondDiffFromServer = Conversions.ToInteger(DateAndTime.DateDiff(DateInterval.Second, DateAndTime.Now, svrobj.GetDateTime()))
        Return True
    Catch ex As Exception
        WriteLog.Log(ex.ToString(), True)
        Return False
    End Try
End Function

And in Xamarin Forms:-

private async Task<bool> EstablishConnectAsync()
{
    try
    {
        var context = new InstanceContext(this);
        svrobj = new WCFEngine.EngineServices.DisplayServicesClient(EngineServices.DisplayServicesClientBase.EndpointConfiguration.DisplayTcpBinding);
        var endpointAddress = new EndpointAddress(modUtility.ServerEndPointAddress);
        svrobj.Endpoint.Address = endpointAddress;
        await svrobj.OpenAsync();
        modUtility.SecondDiffFromServer = (int)(DateTime.Now - await svrobj.GetDateTimeAsync()).TotalSeconds;
        return true;
    }
    catch (Exception ex)
    {
        var error = "Error established connection to WCF services. Ex-" + ex.Message;
        logService.Error(error);
        return false;
    }
}

And from both code, the xamarin forms does not have the context parameter. And it will throw exception at await svrobj.OpenAsync(); with error:-
The method or operation is not implemented.

Can someone assist on what need I do? The application will run between organization network, not having outside of the organization. And to avoid high request traffic every certain interval, our previous colleague use WCF for duplex connection.

Button command bind not working

$
0
0

In my project created a button with command bind when application run on debug mode working fine but after installation of generated signed apk file button command bind not working.

VS Details

Microsoft Visual Studio Community 2019
Version 16.3.2
VisualStudio.16.Release/16.3.2+29326.143
Microsoft .NET Framework
Version 4.8.03752


Insert text to an existing pdf

$
0
0

Hello Everyone,

Is there any way to insert text to an existing pdf in Xamarin.Forms?

How to create and populate a local SQLite db with API json data?

$
0
0

Maybe my question is a comum question, but I didn't find the right answered in any other place.

I'm creating a Xamarin.Forms application that will consume data from an API Rest that I created in C#.

What I'm trying to do is to store all json data returned from the API to a local SQLite db, then I'll use that data in all the application interfaces.

Till here all is well:

public async void GetProduct()
    {
        var httpClient = new HttpClient();
        var response = await httpClient.GetStringAsync("localhost/api/products");
        var product = JsonConvert.DeserializeObject<List<Product>>(response);

        lvProducts.ItemsSource = propriedade;

    }

What I want is to populate a table in local db instead o populating a listview.

Do you have some simple implementable code that I can use to reach this goal? I'm very new in cross-platform development.

Thanks,

Claudionir Queiroz

why does linking SDK assemblies change behavior of database access in EntityFrameWorkCore

$
0
0

Hi all,

I have been working to develop my first Xamarim forms apps for 2 months straight now. So far I have been able to find answers by researching on this forum except for this one.

I used Microsoft.EntityFrameWorkCore.Sqlite to manage an internal database on the device. When I add entities (records) to an instance of my context, or when I call EnsureCreate, no problem if I am running without linking anything (i.e. linker set to none). However when I set linker to link SDK assemblies only, I cannot execute any action on the database be that adding an entity or even calling EnsureCreate. Error message System.ArgumentNullException: 'Value cannot be null.
Parameter name: key'

I really need to publish this app, so I submitted it without any linking. Google Playstore accepted it despite the larger size, but Apple app store rejected it saying that assembly is too large.

I hope someone can help me get back on track.

Remove webview

$
0
0

I am trying to upload to Appstore , but i get this

ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs .


Oke i delete everything that was using Webview , but still i get this error.

Delete the page's and the WKwebview class

Where to look ?

Is it possible to build multiple apps from the same source code (Single Project) in xamarin forms

$
0
0

Hi Guys ,

Is it possible to build multiple apps from the same source code in Xamarin forms
i.e i want to make some changes like login page and want to build different apps for different clients but the same code

i want to build in both Android and ios platforms using Xamarin Form

Please guide me unless i can't start the project

Thanks in Advance.

Dynamic MicroCharts

$
0
0

i'm new in xamarin,how can i set color and value in DonutChart dynamic from api?

Problem while back from one page with horizontal orientation to another page vertical orientation

$
0
0

When I firstly show MainPage it shows properly all and in right orientation. I go to SecondPage, in this page also all is fine. But when I return to previous page( MainPage) orientation doesn't change.

Page 1:

    public partial class MainPage : ContentPage
        {
            public MainPage()
            {
                InitializeComponent();
            }

            async void OnTapGestureRecognizerTapped(object sender, EventArgs args)
            {
                var fullScreenVideoPage = new SecondPage();
                NavigationPage.SetHasNavigationBar(fullScreenVideoPage, false);
                await Navigation.PushAsync(fullScreenVideoPage);
            }

            protected override void OnAppearing()
            {
                base.OnAppearing();
                MessagingCenter.Send(this, "preventLandScape");
            }
        }

XAML for Page 1:

<?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:local="clr-namespace:App1"
             x:Class="App1.MainPage"
             BackgroundColor="Black">


        <StackLayout x:Name="stackLayout" Orientation="Horizontal">
            <Image Source="icon.png"               
                   WidthRequest="150"
                   HeightRequest="150"
                   HorizontalOptions ="CenterAndExpand"
                   VerticalOptions="CenterAndExpand">
                <Image.GestureRecognizers>
                    <TapGestureRecognizer
                        Tapped="OnTapGestureRecognizerTapped"  />
                </Image.GestureRecognizers>
            </Image>     

        </StackLayout>
</ContentPage>

Page 2:

public partial class SecondPage : ContentPage
    {
        public SecondPage()
        {
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();
            MessagingCenter.Send(this, "showLandscapeOrientation");
        }

        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            MessagingCenter.Send(this, "showPortraitOrientation");
        }

        async void OnTapGestureRecognizerTapped(object sender, EventArgs args)
        {
            await Navigation.PushAsync(new NavigationPage(new MainPage()));
        }
    }

MainActivity:

 [Activity(Label = "App1", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
            base.OnCreate(bundle);
            global::Xamarin.Forms.Forms.Init(this, bundle);

            LoadApplication(new App());
            //allowing the device to change the screen orientation based on the rotation
            MessagingCenter.Subscribe<SecondPage>(this, "showLandscapeOrientation", sender =>
            {
                RequestedOrientation = ScreenOrientation.Landscape;
            });

            //during page close setting back to portrait
            MessagingCenter.Subscribe<SecondPage>(this, "preventLandScape", sender =>
            {
                RequestedOrientation = ScreenOrientation.Portrait;
            });

            MessagingCenter.Subscribe<MainPage>(this, "showPortraitOrientation", sender =>
            {
                RequestedOrientation = ScreenOrientation.Portrait;
            });
        }
    }

Change label text or put Entry in paragraph

$
0
0

Hello,

I have a paragraph basically in a label.

"Hello world, This is my first application..."

I would like when I click on "first" to show the keyboard and be able to change the text. Is it possible ?

I have implemented a <Span.GestureRecognizers ... to display a picker but I need the keyboard.

Thank you

Override iOS Accessibility setting for Bold Text

$
0
0

Is there a way to override the Bold Text setting under Accessibility in iOS? Some of our labels are getting truncated.

We have tried setting FontAttributes to None, but that did not make a difference.

Thanks

[UWP] Occasionally an image will display the wrong source, using the bounds of the correct source.

$
0
0

I have many images in my program with sources set to .png files. They all initially load correctly, but sometimes the images will change and display the contents of images I use elsewhere in my application. For example, I will create an image like this:

`

         _image = new Image
        {
            Aspect = Aspect.AspectFit,
            HorizontalOptions = LayoutOptions.CenterAndExpand,
            Source = "Assets/zoom_minus.png"
        };

`

It will initially load fine, but later while running it will change to be a cropped version of another image in the program. It's difficult to reproduce, and just seems to happen after the program has been running for a while. These examples are from an installed appx package, I've never seen this happening during debugging. Does anybody have any idea how to stop this happening? Below are some screenshots of icons loading incorrectly. Apparently a 3 year old account isn't old enough to post links, remove the spaces from the following URLs

us.v-cdn . net/5019960/uploads/editor/kp/ti9rncmpfop2.png
us.v-cdn . net/5019960/uploads/editor/25/tfhvkrm4w8yd.png
us.v-cdn . net/5019960/uploads/editor/z7/up9si9quxnt7.png
us.v-cdn . net/5019960/uploads/editor/jh/39n9t7b59nsu.png
us.v-cdn . net/5019960/uploads/editor/gq/daz5gpuf8tdl.png

Dependency Service: set accessibility focus after a button click

$
0
0

What I want is to be able to set the accessibility focus to a particular element after the click of a button. I tried to achieve that using dependency service, but it doesn't work, I think due to the fact that I try to convert a Forms.View to an Android.View, but I am not sure if it is the problem, maybe I am doing something else wrong. Do you know how to do that, using dependency service or whatever else?

What I tried, (for the moment only on Android):

MainPage:
`public partial class MainPage : ContentPage
{
Button b1;
Button b2;
IAccessibilityFocusService service;

    public MainPage()
    {
    InitializeComponent();

            service = DependencyService.Get<IAccessibilityFocusService>(DependencyFetchTarget.NewInstance);

    b1 = new Button
            {
                Text = "BUTTON 1",
                BackgroundColor = Color.Blue,
            };

            b2 = new Button
            {
                Text = "BUTTON 2",
            };
    stacklayout.Children.Add(b1);
            stacklayout.Children.Add(b2);
    b1.Clicked += Mybutton_Clicked;
}

private async void Mybutton_Clicked(object sender, EventArgs e)
{
        Console.WriteLine("PIPPO clicked");
        service.ChangeAccessibilityFocus(b2); 
    }

}`

IAccessibilityFocusService:
public interface IAccessibilityFocusService { void ChangeAccessibilityFocus(View v); }

AndroidAccessibilityFocus:
`[assembly: Dependency(typeof(CustomViewAccessibility.Droid.AccessibilityFocus))]
public class AndroidAccessibilityFocus : IAccessibilityFocusService

{

    public void ChangeAccessibilityFocus(View v)
    {
    //first I convert the Forms.Veiw to the native android view, so that I can invoke sendAccessibilityEvent on that view.
            Platform.CreateRendererWithContext(v, Android.App.Application.Context).View.SendAccessibilityEvent(EventTypes.ViewFocused); 

    }
}`

Do I need to still include my ExportRenderer for WkWebView

$
0
0

I have a WebView in Xamarin Forms 4.4.0.991477, and it seems like adding and removing this line from AssemblyInfo.cs isn't affecting anything, but do I still need to include [assembly: ExportRenderer(typeof(WebView), typeof(Xamarin.Forms.Platform.iOS.WkWebViewRenderer))] in my AssemblyInfo.cs file to use WkWebView? Or is it automatic?

Thanks!

Viewing all 81910 articles
Browse latest View live


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