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

How to use Spinner in Xamarin Forms

$
0
0

I want to use android Spinner in Xamarin Forms application. How can I do that?


Toolbar with content page

$
0
0

Hello developers,

I am using the component https://github.com/thrive-now/BottomNavigationBarXF

I can't implement a toolbar in one contentpage of my bottomnavigation, example:

<ContentPage.ToolbarItems>
    <ToolbarItem Order="Secondary" Text="Cerrar sesión"  Activated="CerrarSesion"></ToolbarItem>
  </ContentPage.ToolbarItems>

Not showing toolbar...

any solution ?

Regards.

Listview with Entry - Select the listview row(item) and Entry.Text when tap the Entry.

$
0
0

My app is a Xamarin.Forms PCL and I have this challenge that is driving me crazy to solve:

Every time I tap an item of the listview, I need to focus the entry and select everything inside it ("0" at this time).
I also need to select the item if I tap the Entry.

I think the key is get the elements inside the <ViewCell.View> to get access to the Entry and solve the problem with that, but who knows how to get those elements?

My screen is this:

My XAML listview is this:

<ListView x:Name="countsheetListView"
    IsGroupingEnabled="True"
        GroupDisplayBinding="{Binding InventoryGroupName}"
        ItemTapped="countsheetListView_ItemTapped">
        <ListView.GroupHeaderTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                            <Grid BackgroundColor="#EAEAEA" >
                            <Label Text="{Binding InventoryGroupName}" Style="{StaticResource labelGroupTitleStyle}" />
                            </Grid>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.GroupHeaderTemplate>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                            <Grid HeightRequest="30">
                                <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="60*" />
                                        <ColumnDefinition Width="15*" />
                                        <ColumnDefinition Width="15*" />
                                        <ColumnDefinition Width="10*" />
                                </Grid.ColumnDefinitions>
                                <Label Grid.Column="0" Text="{Binding Description}" Style="{StaticResource labelStyle}"/>
                                <Entry Grid.Column="1" x:Name="txtCount" Text="0"  TextColor="Black" FontSize="15" HorizontalTextAlignment="End"    Focused="txtCount_Focused"/>
                                <Label Grid.Column="2" Text="{Binding RecipeUom}"  Style="{StaticResource labelStyle}"/>
                                <Image Grid.Column="3" Source="ic_info.png" HorizontalOptions="End" x:Name="imgSelectCountsheet">
                                        <Image.GestureRecognizers>
                                            <TapGestureRecognizer  NumberOfTapsRequired="1"/>
                                        </Image.GestureRecognizers>
                                </Image>
                            </Grid>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
   </ListView>

This is that kind of irritating issue. Visually extremely simple, but I think I have a lot of work to do to achieve that.
Can anyone help me please?
Thank you anyway

Does Xamarin Forms provide a way to get menu items into the top bar of an UWP application?

$
0
0

Hello,

Does Xamarin Forms provide a way to get menu items into the top bar of an UWP application? In applications such as the mail app, calendar app as well as Groove it is done that way. At the same time, however, the bottom bar should be available.

So far I only have the possibility to get new items in the Bottom Bar via ToolbarItems.Add.

NOTE: It is important to say that in our project XAML is not used and the pages are generated dynamically.

Open a little popup with what I want inside

$
0
0

Hello,
I'm making an application cross-platformes in Xamarin and I need help :smile:

I have an application with Buttons and Labels like the picture.

My question is, how can I open a little popup like this second picture ?

I've already seen this page (DisplayActionSheet) : https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/pop-ups/

I want a popup like the picture to put in some Labels or Picker. Is it possible ?

Thank you very much for your time

Karim

Use Custom Renderer for Label when Text is set via binding

$
0
0

Hi everyone.

I'm developing a cross platform app using Xamarin.Forms and Prism. I'm targeting both Android and iOS. The Android version has been realeased for a couple of months and is stable and fine - no issues there. The iOS version has been started recently and everything is working as expected apart from an issue related to custom label renderers. Sometimes they will work fine and other times they will not work at all

My Problem

I have added the font files to my resources folder and have set the build action to "BundleResource".

Please see an example of my code below.

My custom renderer for a label looks like this.

C#

class CustomLabelRenderer : LabelRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                if (e.NewElement != null)
                {
                    try
                    {
                     Control.Font = UIFont.FromName(@"OpenSans-Regular", (nfloat)e.NewElement.FontSize);
                    }
                    catch (Exception ex)
                    {

                    }
                }
         }
        }
    }

The Try/Catch block is just there for my own sanity at this point

To my knowledge there is nothing wrong with how I have implemented this, I have done essentially the same thing for the Android version of the app and it works without issue.

Where this gets weird for me is here, here are two examples from one of my views

XAML

<cc:CustomLabel FontSize="Medium"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
Text="Homepage"
TextColor="White" />

XAML

<cc:CustomLabel FontSize="Small"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
Text="{Binding CountOfLeadsToActionLabel}"
TextColor="Black" />

In the first example, the catch will not be hit, the label will render with the custom font correctly and it looks fine. In the second example, the only thing that is different is that the text is set to the result of a database call in the ViewModel wired to the View, yet the catch will be hit & the following exception will be thrown.

{System.ArgumentNullException: Value cannot be null.
Parameter name: value
at UIKit.UILabel.set_Font (UIKit.UIFont value) [0x0003b] in /Users/builder/data/lanes/3988/e02d2723/source/xamarin-macios/src/build/ios/native/UIKit/UILabel.g.cs:370
at Onsight.iOS.Renderers.CustomLabelRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x00026] in D:\Development\CRM Suite\MobileCRM\Onsight\Onsight.iOS\Renderers\CustomLabelRenderer.cs:26 }

Here is an example of the property in question, its nothing special. Just a standard property with the Prism magic applied to it

    private string _countOfLeadsToActionLabel;

    public string CountOfLeadsToActionLabel
    {
        get { return _countOfLeadsToActionLabel; }
        set { SetProperty(ref _countOfLeadsToActionLabel, value); }
    }

What I have attempted

In the constructor of the relevant ViewModel I have attempted to assign a default value of String.Empty to the property. I thought it might of had something to do with the value being null, this had no effect.

Created a static class to hold this value and bound the Text property of the cc:CustomLabel to the said property in the static class like so

<cc:CustomLabel FontSize="Small"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
    Text="{x:Static stringResolver:StringResolver.CountOfLeadsToActionLabel}"
TextColor="Black" />

This worked however, it seems very unnecessary and would be a complete pain in the arse to implement across the whole app, since it works perfectly fine on the Android version.

I'm no expert (yet) but based on this my guess is that the problem is occurring because the native UIKit.UILabel is being rendered before the text property is being set and this is causing some sort of error.

Has anyone ever come across this, or something similar? If so, could you share what you did to resolve it? Its not a huge problem as I can handle the error when it occurs and use the default platform font instead. It just means the Android and iOS version look a weird sat side by side.

Thanks in advance for any suggestions.

How to make custom keyboard for Xamarin Forms programmatically-based (not xml) app, targets Android?

$
0
0

Hi,

Sorry, i put this in the discussion section. I think the question section is more appropriate.

I've read the many posts on this forum and on Stackoverflow and other places on making custom keyboards, but have not found an approach that will work for my Xamarin forms cross-platform project. It is programmatically generated. I don't have an xml file. My project targets Android. I have seen solutions for Xamarin Android and for Xamarin projects that are xml based, but i have not seen nor been able to figure out how to do it for Xamarin forms cross platform (my class is app derived from Application) that is programmatically generated.

For example, i built this keyboard that was recommended in several places:

https://github.com/Vaikesh/CustomKeyboard/blob/master/CustomKeyboard/Activity1.cs

It works fine as a standalone, but i have not been able to integrate that into my Xamarin forms app.

I would appreciate any help.

Thank you.

Xamarin Studio deploy App on iPhone

$
0
0

Hi,
I have iPad & iPhone connected to my Mac Mini, iPad is on iOS: 9.3.5 but it does not show in Xamarin Studio for deployment. Do I need to upgrade the iOS version on my iPad to 10.1 ?

If that is the case then when I create the final IPA will it not work with devices running iOS 10.1 ?

please provide your insights ...

-Thanks
Mahesh


Add event to native calendar crossplatform

$
0
0

Dear readers,
i have a question how do i add a event to the native calendar crossplatform i tried
a github project but its not building in my current project.
https://github.com/rid00z/Xamarin.Forms.Calendar
if i tried it that way i gives me compile errors on NativeRender and CalenderPicker.

Does someone has a clue how to do it ?

Thanks in advance,
Stefan

BoxView StyleClass Circle doesnt work on UWP

How to show/hide a view on different screen using Prism EventAggregator?

$
0
0

Hello Everyone!

I'm trying to show/hide a view inside a tab using Prism Event pub/sub.
The first tab contains the main form which hit Save button it "unlocks" the other forms in different tabs by setting IsVisible of StackLayout.

The problem is when IsVisible is changed to True, the StackLayout isn't displayed on screen.

Here is a example:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             xmlns:views="clr-namespace:EventsApp.Views;assembly=EventsApp"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="EventsApp.Views.MainPage"
             Title="MainPage">
    <views:Page1/>
    <views:Page2/>
</TabbedPage>

<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="EventsApp.Views.Page1"
             Title="Page 1">
    <StackLayout>
        <Entry Placeholder="Email address"/>
        <Entry Placeholder="Password" IsPassword="True"/>
        <Button Text="Save" Command="{Binding SaveCommand}"/>
    </StackLayout>
</ContentPage>

<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             xmlns:local="clr-namespace:EventsApp;assembly=EventsApp"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="EventsApp.Views.Page2"
             Title="Page 2">
    <ContentPage.Resources>
        <ResourceDictionary>
            <local:NegateBooleanConverter x:Key="BooleanConverter" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <StackLayout IsVisible="{Binding Locked, Converter={StaticResource BooleanConverter}}">
        <Entry Placeholder="Address"/>
        <Button Text="Save" />
    </StackLayout>
    <StackLayout IsVisible="{Binding Locked}">
        <Label Text="Save Page 1 form first"></Label>
    </StackLayout>
</ContentPage>



public class Page1ViewModel : BindableBase
{
    private readonly IEventAggregator _eventAggregator;
    private readonly IPageDialogService _pageDialogService;

    public Page1ViewModel(IEventAggregator eventAggregator, IPageDialogService pageDialogService)
    {
        _eventAggregator = eventAggregator;
        _pageDialogService = pageDialogService;
    }

    public DelegateCommand SaveCommand => new DelegateCommand(Save);

    private async void Save()
    {
        _eventAggregator.GetEvent<SavedEvent>().Publish(true);
        await _pageDialogService.DisplayAlertAsync("Saved!", "Check other tab now", "OK");
    }
}

public class Page2ViewModel : BindableBase
{
    public Page2ViewModel(IEventAggregator eventAggregator)
    {
        eventAggregator.GetEvent<SavedEvent>().Subscribe(saved => Locked = false);
    }

    private bool _locked = true;
    public bool Locked
    {
        get { return _locked; }
        set { SetProperty(ref _locked, value); }
    }
}

public class SavedEvent : PubSubEvent<bool>
{ }

public class NegateBooleanConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return !(bool) value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return !(bool)value;
    }
}

Estimote SDK for Android , does it work for you ?

$
0
0

Hello guys, i wonder if any of you have managed to make an estimote app that can detect beacons on android/ forms . I have tried using the Xamarin Estimote SDK for android, but never managed to go beyond the ready state for the manager. Did anyone succeed to get some results ?

Unable to resolve dependencies. 'Xamarin.Android.Support.Design 24.2.1'

$
0
0

I see this error in VS2015 after having installed Xamarin and the SDK for Native Xamarin Apps:

Unable to resolve dependencies. 'Xamarin.Android.Support.Design 24.2.1' is not compatible with 'Xamarin.Forms 2.3.2.127 constraint: Xamarin.Android.Support.Design (= 23.3.0)'.

How do I install the newer version of Xamarin.Android.Support.Design?

I can't get my page's title to display in the navigation bar.

$
0
0

I can't tell if this is a bug or if it is a consequence of making a bad architecture decision.

Consider an application with many pages related in this way:

  • FirstPage has some fabulous OpenGL view that does cool stuff. It doesn't have a navigation bar. This includes a button that launches...
  • MenuPage, which displays buttons that launch other forms, but those aren't required for this demo.

There are several things I've tried.

In the initial approach, I start FirstPage the most obvious way (note I'm not wrapping it in a NavigationPage):
public static Page GetMainPage() {
return new FirstPage();
}

FirstPage is really simple, here's just the constructor content:

var lbl = new Label() { Text = "Pretend this is a big complex full-page element." };

var btn = new Button() { Text = "The important thing" };
    btn.Clicked += (s, e) => {
    Navigation.PushModalAsync(new NavigationPage(new MenuPage()));
};

var layout = new StackLayout();
layout.Children.Add(lbl);
layout.Children.Add(btn);

this.Content = layout;

I had to use PushModalAsync() because that seems to be safe if you're not wrapped in a NavigationPage? I'm not sure on that. It could be why I'm having trouble.

I made MenuPage even simpler for the purposes of the demo:
Title = "Menu";

var lbl = new Label() { Text = "asdf" };

var layout = new StackLayout();
layout.Children.Add(lbl);
Content = layout;

With this code, the navigation bar displays on MenuPage, but not the title. The back button doesn't work.

If I modify the PushAsync() call in FirstPage to be PushModalAsync(), I get the title displayed, but the back button on the navigation bar doesn't work anymore.

So I decided that's likely what happens when you don't use NavigationPage start-to-finish, or maybe a side effect of PushModalAsync(). So I changed App:

    public static Page GetMainPage() {
        return new NavigationPage(new FirstPage());
    }

And in FirstPage, used PushAsync() instead. (I also Now the back button works, but MenuPage's Title doesn't show in the navigation bar. If I revert to PushModalAsync(), I get the title but no back button.

Things got more confusing to me when I remembered to put a call to NavigationPage.SetHasNavigationBar() to make sure FirstPage doesn't have the navigation bar, and one in MenuPage to make sure it /does/. If I PushAsync(), I get no navigation bar on either page. If I PushModalAsync(), I get the navigation bar on MenuPage with no title and no back button functionality.

What the heck is going on? Maybe I don't fundamentally understand the difference between modal/non-modal in this context? Maybe your app is supposed to use NavigationPage and always show the navigation bar no matter what? I'm not sure what the right track is.

How Implement System.Net.Sockets and System.Threading.Timer in xamarin forms?

$
0
0

How i can Implement System.Net.Sockets and System.Threading.Timer in xamarin forms. Help me please, I'm new in xamarin.


How to access controls defined in a ListView DataTemplate?

$
0
0

Hi,
Lets say I have a ListView in 'MyView' as follows:

<ListView x:Name="myList" ItemSource="{Binding MyData}">
  <ListView.ItemTemplate>
    <DataTemplate>
      <ViewCell>
        <StackLayout>
          <Label Text="{Binding FieldLabel}"/>
          <Entry x:Name="myEntry" Text="{Binding MyEntry}">
            <b:Interaction.Behaviors>
              <b:BehaviorCollection>
                <b:EventToCommand EventName="Completed" CommandParameter="{Binding .}" Command="{Binding Path=BindingContext.EntryCompletedCommand, Source={x:Reference Name=MyView}}"/>
              </b:BehaviorCollection>
            </b:Interaction.Behaviors>
          </Entry>
        </StackLayout>
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

MyData has x items in it, lets say 10.

How can I set focus to the next entry field to the next item from within the EntryCompletedCommand event? and when the last one is 'completed' then focusing the first entry in the listview?

I've searched for a while now and have not found a straight forward answer!

How to show Loading Indicator in ListDataPage

$
0
0

Hello,
Please I would like to show an ActivityIndicator while ListDataPage data source is being populated in other to tell the user that some activity is going on.

Can anyone help?

Regards

Android Application only displays white screen, iOS works perfectly

$
0
0

I'm experiencing odd behavior after updating some packages (like ReactiveUI 7, Xamarin Forms, SQLitePCL) and after replacing Akavache with my own SQLite implementation. I followed the instructions from Xamarin's documentation to install SQLite-net PCL.

Here's what's happening
The iOS version of the application works just as expected. The Android version launches and definitely executes my a Xamarin Forms application. If I set a breakpoint I can step through execution and see that my data has been successfully fetched from the server and from SQLite. I can step through my application, following execution to completion, yet my display remains white. This is true on both Android device and on the Android simulators.

I do not receive and errors during this process but I do get a lot of activity to my Application Output window which I've save to a gist:
Output Gist

Again, everything works perfectly on my iOS device and I haven't really edited the .iOS & .Droid applications other than to add renderers.

Has anyone dealt with this issue before? Thanks in advance.

**Dependencies **

don´t run

$
0
0

When I run the application it is not able to load the forms. The code was working and tested correctly. What could be happening? Thank you.

Setting button's IsEnabled to false does not disable button

$
0
0

I have observed that when setting a button's IsEnabled property to false, the button continues to be enabled.

This button is located at the bottom of the grid. I do not observe this behavior in other views though.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="auto" />
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <ListView Grid.Row="0"  ItemsSource="{Binding Services}" SelectedItem="{Binding SelectedService}" HasUnevenRows="true">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>

                            <Label Grid.Row="0" Grid.ColumnSpan="2"  Text="{Binding Name}" />
                            <Label Grid.Row="1" Grid.Column="0" Text="Labor:" />
                            <Label Grid.Row="1" Grid.Column="1" Text="{Binding LaborCost, StringFormat='{}{0:c}'}"  />

                            <Label Grid.Row="2" Grid.Column="0" Text="Materials:" />
                            <Label Grid.Row="2" Grid.Column="1" Text="{Binding Materials, Converter={StaticResource MaterialsToCostConverter}, StringFormat='{}{0:c}'}}" />

                            <Label Grid.Row="3" Grid.ColumnSpan="2" Text="{Binding Description}" />
                        </Grid>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

    <Button Grid.Row="1" Grid.Column="0"  Text="Details" IsEnabled="False"
            Command="{Binding ViewService}"/>

</Grid>
Viewing all 91519 articles
Browse latest View live


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