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

Error using JwtSecurityToken

$
0
0

Hi
I'm trying to use custom auth taken from the wonderful book written by adrian hall
https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter2/custom/

But I'm in trouble with the next code in IHttpActionResult Post([FromBody] User body)
.....
System.IdentityModel.Tokens.Jwt.JwtSecurityToken token = Microsoft.Azure.Mobile.Server.Login.AppServiceLoginHandler.CreateToken(
.....

I get an error "Reference to type JwtSecurityToken claims is defined in 'System.IdentityModel.Tokens.Jwt,, but it could not be found"
If I downgrade the nget System.IdentityModel.Tokens.Jwtback to 4.0.20622.1351 I can solve: but how can I solve if I want use the vers. 5.0 ??
Tnx


CAS Authentication

$
0
0

Hi,

We are currently developing a Xamarin, and we have to handle the authentication throught a CAS server. I don't have a clue how to achieve it...

Does someone already had to use CAS authentication on a Xamarin app, and if so, how can I do that ?

Thanks a lot !

TargetFrameworkVersion I need V7.1 not v8

$
0
0

Hello

I am beginner Xamarin but I practice C # windowsforms for years

I installed only what connects Android 7.1 but I get this error

The $(TargetFrameworkVersion) for FormsViewGroup.dll (vv8.0) is greater than the $(TargetFrameworkVersion) for your project (v7.1). You need to increase the $(TargetFrameworkVersion) for your project.

The version 8 does not interest me I wish the version 7.1 as well on the emulator as on live player

My problem is that I can not find a trace of the v8 in the configuration of my project

How can I configure my project on version 7.1?

thanks in advance

ASMX service very slow on first call

$
0
0

I have an ASMX service. Proxy class uses SoapHttpClientProtocol Invoke().

The first request from my app is very slow (0.5-2 minutes). The next requests are fast (1 second). This is regardless of HTTPS or HTTP.

A packet sniffer shows that it takes 17 seconds from I call the first request, until my app sends the first packet.

Output window:

03-23 10:28:50.018 D/Mono ( 2358): Image addref Mono.Security[0xd1221ba0] -> Mono.Security.dll[0xd126ff00]: 2
03-23 10:28:50.018 D/Mono ( 2358): Prepared to set up assembly 'Mono.Security' (Mono.Security.dll)
03-23 10:28:50.018 D/Mono ( 2358): Assembly Mono.Security[0xd1221ba0] added to domain RootDomain, ref_count=1
03-23 10:28:50.019 D/Mono ( 2358): AOT: image 'Mono.Security.dll.so' not found: dlopen failed: library "/data/app/com.example.MyApp-1/lib/x86/libaot-Mono.Security.dll.so" not found
03-23 10:28:50.019 D/Mono ( 2358): AOT: image '/usr/local/lib/mono/aot-cache/x86/Mono.Security.dll.so' not found: dlopen failed: library "/data/app/com.example.MyApp-1/lib/x86/libaot-Mono.Security.dll.so" not found
03-23 10:28:50.020 D/Mono ( 2358): Config attempting to parse: 'Mono.Security.dll.config'.
03-23 10:28:50.020 D/Mono ( 2358): Config attempting to parse: '/usr/local/etc/mono/assemblies/Mono.Security/Mono.Security.config'.
03-23 10:28:50.020 D/Mono ( 2358): Assembly Ref addref System[0xe577af80] -> Mono.Security[0xd1221ba0]: 2
Loaded assembly: Mono.Security.dll [External]
03-23 10:28:50.020 D/Mono ( 2358): Assembly Ref addref Mono.Security[0xd1221ba0] -> mscorlib[0xea20a340]: 52
03-23 10:28:50.036 D/Mono ( 2358): Assembly Ref addref Mono.Android[0xe5779780] -> System[0xe577af80]: 14

By the way, when I use HttpWebRequest and manually write SOAP envelope and parse XML it is much faster even the first time (2-3 seconds). But much more work to maintain, so I rather not use this method.

Label position and text alignment

$
0
0

Hi,

I try to right align text under Label but can't find how do this. I try to make 3 label like this :

Label 1 | Label 2 | Label 3

Here is my layout

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="BasicForm.MainPage">
    <ContentPage.Content >

            <StackLayout Spacing = "0" Padding="10, 40, 10, 40" BackgroundColor="Green" Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="Start">
                <Label x:Name="start" Font="Large" Text="t" HorizontalOptions="FillAndExpand" VerticalOptions="Center"></Label>
                <Label x:Name="middle" Font="Large" TextColor="Red" Text="e" HorizontalOptions="Center" VerticalOptions="Center"></Label>
                <Label x:Name="end" Font="Large" Text="st" HorizontalOptions="FillAndExpand" VerticalOptions="Center"></Label>
            </StackLayout>

    </ContentPage.Content>
</ContentPage>

Label 2 contain only one letter so it have to be on center of the screen. Label 1 is the start of the word (align right) and Label 3 the end of the word.

Any ideas for a workaround when sizing incorrect for Entry in ScrollView in Grid on UWP

$
0
0

I have a complex page layout that involves a Grid into which I dynamically insert other Layouts/Views. On iOS and Android, this works fine, but on UWP I hit a problem when inserting an Entry (nested in a ScrollView) that is bound to a non-Empty string. In that situation, the height of the Entry does not take into account the FontSize of the text in the Entry.

I've simplified the code down to the following, where an instance of BugUWPEntryBindingPageView gets pushed onto the navigation stack.
If the Entry is bound to ValueOne (initially a non-empty string) the height of the Entry is incorrect when the Entry is added to the Grid.
If the Entry is bound to ValueTwo (initially an empty string) the height of the Entry is correct.

This looks like a Xamarin.Forms bug to me (I'm using XF 2.4.0), but (other than always starting with an empty string and later setting the correct value in the ViewModel) has anybody got any ideas for a workaround? (I don't want to wait for Xamarin to release a fix before getting this particular page working as expected)

using Xamarin.Forms;

namespace ViewsUsingXamarinForms
{
    public class BugUWPEntryBindingViewModel
    {
        public BugUWPEntryBindingViewModel()
        {
            ValueTwo = string.Empty;
            ValueOne = "123";
        }

        public string ValueOne { get; set; }
        public string ValueTwo { get; set; }

    } // public class BugUWPEntryBindingViewModel

    public class BugUWPEntryBindingPageView : ContentPage
    {
        private static readonly BugUWPEntryBindingViewModel ViewModel = new BugUWPEntryBindingViewModel();

        private Grid _grid;

        protected override void OnAppearing()
        {
            _grid = new Grid
            {
                BackgroundColor = Color.White,
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions = LayoutOptions.FillAndExpand,
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition { Width = GridLength.Star },
                },
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {Height = GridLength.Auto },
                    new RowDefinition {Height = GridLength.Star }
                },
            };

            _grid.Children.Add(
                new Button
                {
                    Text = "Add/replace entries",
                    BackgroundColor = Color.Blue,
                    TextColor = Color.White,
                    Command = new Command(OnAddEntries)
                }, 0, 1, 0, 1);

            BindingContext = ViewModel;
            Content = _grid;
        }

        private void OnAddEntries()
        {
            Entry entry = new Entry
            {
                FontFamily = "Verdana", //DeviceWrapper.DefaultFontFamily,
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Entry)),
            };
            entry.SetBinding(
                Entry.TextProperty,
                new Binding(
                    nameof(BugUWPEntryBindingViewModel.ValueOne),
                    BindingMode.TwoWay,
                    null,
                    string.Empty));
            _grid.Children.Add(
                new ScrollView
                {
                    Content = new StackLayout
                    {
                        Children =
                        {
                            entry
                        }
                    }
                }, 0, 1, 1, 2);
        }
    }
}

How to place an Absolute Layout inside a Stack Layout

$
0
0

Hello there! So what I'm trying to accomplish is the following: I have a scrollview with a stack layout inside it, and I'd like to create multiple absolute layouts which each wrap around a group of elements, which would then be added into the stack layout. For the sake of clarification consider something like Instagram's homepage, where you have Posts composed of an Image, the User's Name on top of It, and the comments section beneath it. Ideally, I'd like to create those "post" objects and have them wrapped inside an absolute layout, which in turn would be stacked inside a stacklayout, which would be scrollable (inside a scroll view). Now, I'm not sure if the way I'm implementing it is the best way to do so, but any help would be appreciated.

Code looks something like this

`

    <StackLayout x:Name="StackLayout_Container"
                 HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
                 Spacing="10"
                 Padding="5"
                 ></StackLayout>

</ScrollView>`

I then create CardObjects as needed with each containing its own absolute layout, and later have them added to the StackLayout. This works, but for some reason the views inside the absolutelayout (images, labels ..etc) end up being too small and aren't positioned correctly, and the scrollview isn't scrollable. Any help is appreciated

ScrollView not updating when elements are changed on Android

$
0
0

I have a ContentPage, with a ScrollView that has a StackLayout with a couple of nested StackLayouts.

Essentially:

public class Widgets : ContentPage
{
    StackLayout layout;
    public Widgets()
    {
        layout = new StackLayout()
        {
            VerticalOptions = LayoutOptions.FillAndExpand,
            Orientation = StackOrientation.Vertical
        };

        var Widget = new Wiget();
        layout.Children.Add(Widget.Render());
        //Widget.Render() returns a StackLayout with some other UI elements, it also loads some items from the web and adds them to the stacklayout. 

        var Widget2 = new Wiget2(); //Same idea...
        layout.Children.Add(Widget2.Render());

        Content = new ScrollView()
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            Content = layout
        };
    }
}

When the Widget class finishes loading the web items, and adds them to the stacklayout, the new elements are not rendered, in fact any change to the UI does not get rendered. The widgets display a Loading icon while the items are loading, this is displayed properly and the loading icon disappears when loading is complete, but the new elements do not show up.

This appears this when running on Android, the ScrollView and related Widget elements work properly on iOS. Admittedly I can only try Android on the emulator so not sure if it is an issue with it. I am using the built-in Android_Accelerated_Nougat with API version 25. (7.1.1)


iOS Binding Library in Xamarin Forms project

$
0
0

I have a binding library that works fine in a Xamarin iOS project, but if I try to use it in a Xamarin Forms project, the application crashes with a SIGSEGV every time as soon as the library is accessed.

Are there any special concerns to take into account when using a binding library with a Forms app?

How to use OnIdiom to reference OnPlatform data in XAML?

$
0
0

I'm trying to set different text size, for each different platform & form factor in the application wide ResourceDictionary

<OnPlatform x:Key="myfontsize-phone" x:TypeArguments="x:Double" iOS="20" Android="20" WinPhone="30"/> <OnPlatform x:Key="myfontsize-tablet" x:TypeArguments="x:Double" iOS="40" Android="40" WinPhone="60"/> ... <OnIdiom x:Key="myfontsize" x:TypeArguments="x:Double" Phone="{StaticResource myfontsize-phone}" Tablet="{StaticResource myfontsize-tablet}"/>

and in my page XAML, i just call it with

<Label Text="SomeText" FontSize="{StaticResource myfontsize}"/>

The code above compile alright, but on run time I encountered with "System.InvalidCastException: Specified cast is not valid" in my page's InitializeComponent(). If I take out the reference to the and reference to the item instead, it will work alright.

This is what I get in the debug log, which isn't much help
09-01 20:56:01.292 E/mono (15401): Unhandled Exception: 09-01 20:56:01.292 E/mono (15401): System.InvalidCastException: Specified cast is not valid. 09-01 20:56:01.292 E/mono (15401): at (wrapper dynamic-method) System.Object:be601f56-8ff2-4aab-a41a-aababab502f5 (intptr,intptr,intptr) 09-01 20:56:01.292 E/mono (15401): at (wrapper native-to-managed) System.Object:be601f56-8ff2-4aab-a41a-aababab502f5 (intptr,intptr,intptr) 09-01 20:56:01.294 E/mono-rt (15401): [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidCastException: Specified cast is not valid. 09-01 20:56:01.294 E/mono-rt (15401): at (wrapper dynamic-method) System.Object:be601f56-8ff2-4aab-a41a-aababab502f5 (intptr,intptr,intptr) 09-01 20:56:01.294 E/mono-rt (15401): at (wrapper native-to-managed) System.Object:be601f56-8ff2-4aab-a41a-aababab502f5 (intptr,intptr,intptr)

Any clue on what might have gone wrong?

how to highlight code syntax in Xamarin.Forms Text editor

$
0
0

Hello
I would like to know how can I highlight code in Xamarin.Forms Text Editor like in web-application we highlight output code of textbox using Highlight.js in HTML view?
Is this possible in Xamarin?
I need to place some formatted code with syntax highlighting in my xamarin.forms application.

Adding the badge count to the toolbar icon?

$
0
0

Can any one please help me how to add the count to the tool bar icon in xamarin.forms?

Thanks in advance.

I have a problem with Grid on Android simulator

$
0
0

Hello.
Can you help me?
I have XAML with simple Grid:

<Grid HorizontalOptions="Fill" VerticalOptions="Center" Padding="40" RowSpacing="10" ColumnSpacing="10">
    <Grid.RowDefinitions>
        <RowDefinition Height="2*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Label TextColor="White" 
           HorizontalOptions="Center"
           FontAttributes="Bold" 
           FontSize="50"
           Grid.Row="1"
           Grid.Column="0"
           Grid.ColumnSpan="3" Text="12345"></Label>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="1" Grid.Column="0" Grid.Row="3"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="2" Grid.Column="1" Grid.Row="3"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="3" Grid.Column="2" Grid.Row="3"></Button>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="4" Grid.Column="0" Grid.Row="4"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="5" Grid.Column="1" Grid.Row="4"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="6" Grid.Column="2" Grid.Row="4"></Button>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="7" Grid.Column="0" Grid.Row="5"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="8" Grid.Column="1" Grid.Row="5"></Button>
    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="9" Grid.Column="2" Grid.Row="5"></Button>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#fff" BorderRadius="30" Text="0" Grid.Column="1" Grid.Row="6"></Button>

    <Button FontSize="30" TextColor="#28282c" BackgroundColor="#96ca2d" BorderRadius="30" Text="Dial" Grid.ColumnSpan="3" Grid.Row="7"></Button>
</Grid>

When I run this XAML on iOS simulator, I haven't problems. But when I run on Android, I have problems with grid height.

Having issues in android on logout flow

$
0
0

Hi,

I have a Xamarin forms app which is based on MasterDetailPage, whereas it's Detail is a TabbedPage.
When app loads I set the Main page as follows:

    MainPage = IsUserLoggedIn ? new MainPage() : (Page) new LogInPage();

Upon login everything works fine.

I've recently added a logout button located on MasterPage's Master, and handled it as follows (in LogOutPage):

    protected override void OnAppearing()
    {
        App.IsUserLoggedIn = false;

        App.Current.MainPage = new LogInPage();
    }

On iOS it works great, directing the user to the LogInPage.

However in Android I get the following error: (which refers to this line: 'App.Current.MainPage = new LogInPage();')

'Java.Lang.IllegalStateException: Recursive entry to executePendingTransactions'

I'll appreciate any help on that.

How to implement speech(voice)-to-text using xamarin.Forms

$
0
0

Hello Guys. please help, how do i implement a speech(voice) and textbox gets the text in my application.


xamarin forms Device.Starttimer vs .net standard System.Timers

$
0
0

I wonder if somebody has a experience with .net standard system timer and compare with device.starttimer. I have the feeling that Xamarin forms device timer is not optimized and having often high memory usage although i handle return false correctly which supposed to dispose the timer. Does anybody used System.Timers as we have .net standard now? I wonder how are they converted into native libraries?

Package restore failed. Rolling back package changes

$
0
0

Can anyone please help me
Why I am geting the error "Package restore failed. Rolling back package changes" for project name, While i am installing the plugin .current activity. idea? Please let me know.

Thanks in dvance.

Master Detail - Missing Page List in Release Builds

$
0
0

I've got a master detail page setup. The hamburger menu slides in a list of pages available. Each page opens the same ContentPage but with a different title and ID, which then grabs data from a SQLite DB.

The list is generated in the following manner

using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace ui.main
{
    public partial class MasterPage : ContentPage
    {
        public sqlite.subscribedTopicsDatabase _topics = new sqlite.subscribedTopicsDatabase();
        public ListView ListView { get { return listView; } }

        public MasterPage()
        {

            InitializeComponent();
            SetupUI();
        }

        /// <summary>
        /// Setups the user interface.
        /// </summary>
        async void SetupUI()
        {

            // Get topics
            var topics = await _topics.GetAllsubscribedTopics();

            var masterPageItems = new List<MasterPageItem>();

            masterPageItems.Add(new MasterPageItem
            {
                Title = "All",
                Topic = -1,
                //IconSource = "contacts.png",
                TargetType = typeof(AllTopicsPage)
            });

            for (int i = 0; i < topics.Count; ++i)
            {
                System.Diagnostics.Debug.WriteLine("I have topic: " + topics[i].name);
                masterPageItems.Add(new MasterPageItem
                {
                    Title = topics[i].name,
                    Topic = topics[i].apiID,
                    TargetType = typeof(TopicDetailPage)
                });
            }

            listView.ItemsSource = masterPageItems;
        }
    }
}

On a debug build, the items appear, on a release build, they do not. See screenshots.

Debug Build
Debug Build

Release Build
Release Build

What could be causing this?

Keyboard hides input in Xamarin Forms

$
0
0

I'm facing the problem that I have entrys at the bottom of the screen, which when the keyboard pops ups it completely hides the entrys while the user is typing the values.

I found this link on the fix in iOS:

http://forums.xamarin.com/discussion/15067/keyboard-hides-inputs

Anyone have an idea for the best way to resolve this via forms? Renderer?

Thanks in advance!

Xamarin Forms: Button event sequence and Command

$
0
0

Hi,

I have a simple custom button that adds a pressed animation effect. However, I have found that it would sometimes still be busy with the animation when it fires the Command bound to this control, which results in the weird freezing artefact of the animation.

The sequence of events seems to be Pressed, Released(Command), , Clicked but because my animation runs async, the pressed is triggered while the animation still runs, the Command is invoked while the animation is still running.

To try and fix this, I have intercepted the Command, and I then invoke it myself.

        public RoundedButton() : base()
        {
            this.Pressed += AnimateButtonPress;
            this.Released += OnReleased;
        }

        private async void AnimateButtonPress(object sender, EventArgs e)
        {
            try
            {
                ButtonCommand = Command;
                Command = null;
                if (Animate &&
                    !isAnimating)
                {
                    isAnimating = true;
                    await this.ScaleTo(1.1, 70, Easing.Linear);
                    await this.ScaleTo(1, 30, Easing.BounceOut);
                    isAnimating = false;
                }
                if (ButtonCommand != null &&
                    ButtonCommand.CanExecute(CommandParameter))
                {
                    ButtonCommand.Execute(CommandParameter);
                }
            }
            finally
            {
                Command = ButtonCommand;
            }
        }

Is this a good idea? Or is there any other way of doing it

Viewing all 77050 articles
Browse latest View live


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