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

How to handle navigation with tabbedpage

$
0
0

I'm using Prism's INavigationSerivce, so I'm totally confused about how to deal with tabbed page navigation. Typically (for pages that aren't part of a TabbedPage), I'm implementing INavigationAware, so my pages has OnNavigatedTo(..). From there I can make service calls or do whatever.

And that's fine for the intial page of a TabbedPage, b/c I actually use NavigationService to get there:

_navigationSerivce.NavigateAsync("SomeTabbedPage/ContentPageWithinTabbedPages")

But once you're there, and you tab any of the tabbed page heading to go to another page in the collection, you're no longer navigating, so you don't get notified. I do realize that TabbedPage exposes a CurrentPageChanged, but that would force me to put logic in the codebehind and destroys the MVVM pattern Prism is trying to encourage.

How is one supposed to handle this?


Problem with XamlCTask - solution don't compile after update to 1.4.3-pre2

$
0
0

Hi all

I work with VS and have a shared-project.
After update to 1.4.3-pre2 (without change anything), I was not able to compile anymore (not Android, not iOS and not WP).
I have lost now over a full day to try solve the problem and finally have found a solution (at least for my problem).
Therefore, I post the steps here for all other users.

Error-message:

Die Xamarin.Forms.Build.Tasks.XamlCTask-Aufgabe konnte nicht aus der M:\SW\VS_2013\Xamarin\MatrixGuide\packages\Xamarin.Forms.1.4.3.6358-pre2\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Build.Tasks.dll-Assembly geladen werden. Stellen Sie sicher, dass die -Deklaration korrekt ist, die Assembly und alle zugehörigen Abhängigkeiten verfügbar sind und die Aufgabe eine öffentliche Klasse enthält, die Microsoft.Build.Framework.ITask implementiert. M:\SW\VS_2013\Xamarin\MatrixGuide\packages\Xamarin.Forms.1.4.3.6358-pre2\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets 56 3 MatrixGuide.Android

same error-message in all projects.
Important note: I you have this problem, you also may have some other error-messages.
I then have searched the internet and found a entry in StackOverflow:

  • Close solution, delete \bin\, \obj. and \packages\ folder (NuGet) and restart VS
    => I have done this, but this don't have solved my problem

To solve the problem I had to:

  • close the solution in VS

    • open the files:
    • AppName.Android.csproj
    • AppName.iOS.csproj
    • AppName.Winphone.csproj
      in the sub-folders of the solution with editor.
      Then I had to remove (just delete) two old references (1.2.3.6257) .to .forms:

      <Import Project="....\packages\Xamarin.Forms.1.2.3.6257\build\portable-win+net45+wp80+MonoAndroid10+MonoTouch10\Xamarin.Forms.targets"

    and

    Condition="Exists('....\packages\Xamarin.Forms.1.2.3.6257\build\portable-win+net45+wp80+MonoAndroid10+MonoTouch10\Xamarin.Forms.targets')" />

Where it seems, as the deletion of the import has done the job...
Note: there were also references to the new version stored in the .csproj-file.
Then reopen the solution in VS, clean and rebuild.
With these manual changes, I'm now able to further build for all platforms.

No idea how the false (old) references were added to the .csproj-file (or were not removed automatically by update to Pre-2)

So, if you have similar problems, I suggest you, to first only manually clean the .csproj-files.
If this don't solve the problem, try also to delete \obj\, \bin\, and \packages- folder (but I don't think, that this is necessary)

Hope this helps some other users... :sunglasses:

Is it possible to override base class ContentPage's Content property?

$
0
0

In my main class (which inherits from ContentPage), I've defined variable named "Content" of type View. This variable has a setter.

The goal is to override the base's Content property (of ContentPage), so when XAML writes to the Content property of the control, the setter intercepts the value and instead applies it to another property.

This implementation worked in Forms 2.0 but I upgraded to the most recent Forms and I can't seem to get it to work now. I've placed a break point in the setter and it is not being called at all.

Thanks for any help!

Close Keyboard when SearchBar.Text is Empty

$
0
0

I know this is going to sound familiar as there have been a number of entries in the forum but none of them address this issue in its entirety.

I have a page with a SearchBar and ListView in a StackLayout.

When you click in the SearchBar the keyboard comes up = Good

If I type in characters and then click Cancel the keyboard goes away = Good

If there are no characters in the SearchBars Text Box there is no way to clear the keyboard.

The canned answer is searchBar.Unfocus() but there is not great place to do this without adding another button which is pretty hokey.

I have seen a good example of a custom renderer for Entry that adds a toolbar and a Done button to the keyboard (in iOS) so you can click it to close the keyboard. That would be okay except SearchBar does not seem to have a Keyboard property to get to it to do this.

I saw an excellent renderer that looked like it would work for Android but I need iOS also.

I have seen some other posts that discuss using a Gesture. I thought that if I put a gesture on the ListView when SearchBar gets focus I could use it to capture a tap and call SearchBar.Unfocus(). I have not been able to get this to work. Here is the parts of my code that do this (sorry in advance for whatever mangling may occur).

// Gesture recognizer
TapGestureRecognizer searchBarTapGestureRecognizer;
searchBarTapGestureRecognizer = new TapGestureRecognizer();
searchBarTapGestureRecognizer.Tapped += (s, e) =>
{
searchBar.Unfocus();
contactsListView.GestureRecognizers.Remove(searchBarTapGestureRecognizer);
};

        searchBar.Focused += (s, e) =>
        {
            contactsListView.GestureRecognizers.Add(searchBarTapGestureRecognizer);
        };

I can hit a breakpoint on the Add in Focused() event so I know the gesture is added however if I put a breakpoint in the Tapped event of the Gesture it does not fire. It seems to fire the ItemSelected() event as normal.

I was hoping that if I applied a Gesture that I would get that before anything else happened with the control? Maybe I am wrong.

Does anyone have any suggestions on how I can get a more standard operation with a tap off from the search bar or a way to get the Done button on the iOS keyboard when it is shown from a SearchBar?

Thanks,

Carl

Label Navigation to new page

$
0
0

Hello everyone I am new to Xamarin. I have worked on XAML before for Windows and Windows Phone apps. For native windows/windows phone apps there is a click, pointer released, pointer pressed, tapped, etc properties for a textblock to naviagte to a new page..But here in Xamarin.forms XAML, I cant find a property for navigating to another page using label. Can anyone help me?

OnAppLinkRequestReceived never gets called

Confusion between Custom Renderes x Behaviors x ViewModel x Converters

$
0
0

I have to manipulate a user input to create a mask while user is typing.. It would be possible to do this in the following ways:

Behaviors:

public class TestBehavior : Behavior<Entry>
    {
        protected override void OnAttachedTo(Entry bindable)
        {
            bindable.TextChanged += TextChanged;
        }

        protected override void OnDetachingFrom(Entry bindable)
        {
            bindable.TextChanged -= TextChanged;
        }

        private void TextChanged(object sender, TextChangedEventArgs e)
        {
            //manipulate ((Entry)sender).Text here
        }
    }

Custom Renderers(Custom entry):

public class CustomEntry : Entry
    {
        public CustomEntry()
        {
            base.TextChanged += OnTextChanged;
        }

        public void OnTextChanged(object sender, TextChangedEventArgs args)
        {
            Entry entry = sender as Entry;
            string text = entry.Text;

            //manipulate text here
        }
    }

DataBindind(ViewModel???)

public class DecimalEntryViewModel : INotifyPropertyChanged
    {
        string displayText = "";

        public string DisplayText
        {
            set
            {
                if (displayText != value)
                {
                    displayText = Parse(value);
                    OnPropertyChanged("DisplayText");
                }
            }
            get { return displayText; }
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private string Parse(string str)
        {
            //manipulate str here
        }
    }

And maybe with Converters?

I am confused with which design pattern I will use to achieve a mask control. Also when use one and not the other, since in some cases it is possible to do both. In this case, its possible to call TextChanged event in all.

Best way to do reusable controls? ContentView vs ControlTemplate ?

$
0
0

I am using Contentview when I need reusable controls as shown below.

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:c="clr-namespace:myApp;assembly=myApp"
                 x:Class="myApp.APage" > 
        <ContentPage.Content>     
            <c:cvReusableView   />
           ...

and contentview

 <?xml version="1.0" encoding="utf-8" ?>
            <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
                         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                         x:Class="myApp.cvReusableView   ">

              <ContentView.Content>
                <StackLayout Orientation="Horizontal"  BackgroundColor="White">
                  <RelativeLayout  Style="{StaticResource myStyle}"   
       HorizontalOptions="Start" VerticalOptions="Center" >
</ContentView.Content>

But I can do that as below using ControlTemplate defined in app.xaml?

<ControlTemplate x:Key="MyControlTemplate">
        <StackLayout Orientation="Horizontal"  BackgroundColor="White">
                      <RelativeLayout HorizontalOptions="Start" VerticalOptions="Center" />
    </StackLayout>
      </ControlTemplate>

and binding this ControlTemplate to ContentView

      <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                     xmlns:c="clr-namespace:myApp;assembly=myApp"
                     x:Class="myApp.APage" > 
            <ContentPage.Content>     
    <ContentView ControlTemplate={StaticResource MyControlTemplate}/>

What are the pros and cons for each method? I always imagine that if I define so many resource or controls in app.xaml, this is cached during the application load and it may increase memory usage. Of course since things are cached, rendering should be faster. thats why I avoid using so much in app.xaml unless i really use the resource on all views. Am I correct with my opinion?


ORM using SQLite supporting Foreign Key added (Announcement)

$
0
0

An SQLite ORM (SQLite-Net Extensions) supporting Foreign key has been added.

Features:

  1. Supports UWP (Win 10)
  2. Uses sqlite-net-pcl by Frank A. Krueger (Xamarin recommended)

Note: Original ORM developed by TwinCoders doesn't support above 2 features.

Author: Martin Kuckert

Xamarin.forms datepicker how do I set the MaximumDate property in XAML to only accept today?

$
0
0

Hey all,

Well I am making validators for my application, though the datepicker has a maximumDate property which I can set. Does anybody know how to set this to today in XAML?

Currently have this:

<DatePicker x:Name="DatePicker"
                                TextColor="{StaticResource TextColor}"
                                Opacity="0.87"
                                MaximumDate="Today">

Cheers luuk

Xamarin.Forms Bindable Picker

$
0
0

If anyone wonders how to make a Bindable Picker, here's the code:

`

public class BindablePicker : Picker
{
    #region Fields

    //Bindable property for the items source
    public static readonly BindableProperty ItemsSourceProperty =
        BindableProperty.Create<BindablePicker, IEnumerable>(p => p.ItemsSource, null, propertyChanged: OnItemsSourcePropertyChanged);

    //Bindable property for the selected item
    public static readonly BindableProperty SelectedItemProperty =
        BindableProperty.Create<BindablePicker, object>(p => p.SelectedItem, null, BindingMode.TwoWay, propertyChanged: OnSelectedItemPropertyChanged);

    #endregion

    #region Properties

    /// <summary>
    /// Gets or sets the items source.
    /// </summary>
    /// <value>
    /// The items source.
    /// </value>
    public IEnumerable ItemsSource
    {
        get { return (IEnumerable)GetValue(ItemsSourceProperty); }
        set { SetValue(ItemsSourceProperty, value); }
    }

    /// <summary>
    /// Gets or sets the selected item.
    /// </summary>
    /// <value>
    /// The selected item.
    /// </value>
    public object SelectedItem
    {
        get { return GetValue(SelectedItemProperty); }
        set { SetValue(SelectedItemProperty, value); }
    }

    #endregion

    #region Methods

    /// <summary>
    /// Called when [items source property changed].
    /// </summary>
    /// <param name="bindable">The bindable.</param>
    /// <param name="value">The value.</param>
    /// <param name="newValue">The new value.</param>
    private static void OnItemsSourcePropertyChanged(BindableObject bindable, IEnumerable value, IEnumerable newValue)
    {
        var picker = (BindablePicker)bindable;
        var notifyCollection = newValue as INotifyCollectionChanged;
        if (notifyCollection != null)
        {
            notifyCollection.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    foreach (var newItem in args.NewItems)
                    {
                        picker.Items.Add((newItem ?? "").ToString());
                    }
                }
                if (args.OldItems != null)
                {
                    foreach (var oldItem in args.OldItems)
                    {
                        picker.Items.Remove((oldItem ?? "").ToString());
                    }
                }
            };
        }

        if (newValue == null) 
            return;

        picker.Items.Clear();

        foreach (var item in newValue)
            picker.Items.Add((item ?? "").ToString());
    }

    /// <summary>
    /// Called when [selected item property changed].
    /// </summary>
    /// <param name="bindable">The bindable.</param>
    /// <param name="value">The value.</param>
    /// <param name="newValue">The new value.</param>
    private static void OnSelectedItemPropertyChanged(BindableObject bindable, object value, object newValue)
    {
        var picker = (BindablePicker)bindable;
        if (picker.ItemsSource != null)
            picker.SelectedIndex = picker.ItemsSource.IndexOf(picker.SelectedItem);
    }

    #endregion
}

`

Usage is pretty straight forward..:

<local:BindablePicker ItemsSource="{Binding Cats}" SelectedItem="{Binding SelectedCat}"/>

It would've been nice that the Xamarin.Forms.Picker already had this functionality, maybe we'll see it in a next update...

Any questions, comments, or contributions are welcome :)

error: package android.support.v7.internal.widget.ActivityChooserModel does not exist

$
0
0

I just upgraded my project to Xamarin.Forms 2.3.0.49 and now I started getting these errors when I rebuild my Droid project:

 obj\Release\android\src\mono\android\support\v7\internal\widget\ActivityChooserModel_OnChooseActivityListenerImplementor.java:8: error: package android.support.v7.internal.widget.ActivityChooserModel does not exist
2016-06-29T04:11:05.9052860Z                android.support.v7.internal.widget.ActivityChooserModel.OnChooseActivityListener
2016-06-29T04:11:05.9052860Z                                                                       ^
2016-06-29T04:11:05.9209120Z          obj\Release\android\src\mono\android\support\v7\internal\widget\ActivityChooserModel_OnChooseActivityListenerImplementor.java:28: error: package android.support.v7.internal.widget does not exist
2016-06-29T04:11:05.9209120Z            public boolean onChooseActivity (android.support.v7.internal.widget.ActivityChooserModel p0, android.content.Intent p1)
2016-06-29T04:11:05.9209120Z                                                                               ^
2016-06-29T04:11:05.9209120Z          obj\Release\android\src\mono\android\support\v7\internal\widget\ActivityChooserModel_OnChooseActivityListenerImplementor.java:33: error: package android.support.v7.internal.widget does not exist
2016-06-29T04:11:05.9209120Z            private native boolean n_onChooseActivity (android.support.v7.internal.widget.ActivityChooserModel p0, android.content.Intent p1);
2016-06-29T04:11:05.9209120Z                                                                                         ^
2016-06-29T04:11:05.9209120Z          obj\Release\android\src\mono\android\support\v7\internal\widget\FitWindowsViewGroup_OnFitSystemWindowsListenerImplementor.java:8: error: package android.support.v7.internal.widget.FitWindowsViewGroup does not exist
2016-06-29T04:11:05.9209120Z                android.support.v7.internal.widget.FitWindowsViewGroup.OnFitSystemWindowsListener
2016-06-29T04:11:05.9209120Z                                                                      ^
2016-06-29T04:11:05.9209120Z          obj\Release\android\src\mono\android\support\v7\internal\widget\ViewStubCompat_OnInflateListenerImplementor.java:8: error: package android.support.v7.internal.widget.ViewStubCompat does not exist
2016-06-29T04:11:05.9209120Z                android.support.v7.internal.widget.ViewStubCompat.OnInflateListener
2016-06-29T04:11:05.9209120Z                                                                 ^
2016-06-29T04:11:05.9209120Z          obj\Release\android\src\mono\android\support\v7\internal\widget\ViewStubCompat_OnInflateListenerImplementor.java:28: error: package android.support.v7.internal.widget does not exist
2016-06-29T04:11:05.9209120Z            public void onInflate (android.support.v7.internal.widget.ViewStubCompat p0, android.view.View p1)
2016-06-29T04:11:05.9209120Z                                                                     ^
2016-06-29T04:11:05.9209120Z          obj\Release\android\src\mono\android\support\v7\internal\widget\ViewStubCompat_OnInflateListenerImplementor.java:33: error: package android.support.v7.internal.widget does not exist
2016-06-29T04:11:05.9209120Z            private native void n_onInflate (android.support.v7.internal.widget.ViewStubCompat p0, android.view.View p1);

In my Droid project I have the dependencies configured as follows:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Forms" version="2.3.0.49" targetFramework="monoandroid60" />
</packages>

Which is exactly the same version Xamarin.Forms 2.3.0.49 asks.

Any idea of why it complains about theses classes not found?

Weird error that only can be solved by uninstalling app.

$
0
0

Hi all,

Im facing this really weird error. Almost every time i run the app (Android and iOS) it crashes and give me this errors:

Android:
https://gist.github.com/edgargonzalez17/117bc4aaa95b98dd243c6ab0499774a5

iOS:
https://gist.github.com/edgargonzalez17/9f3039731dddae263328fa179e24a8e8

The only way to fix this is by uninstalling the app. I've tried everything, from cleaning solution, to switch XS version(i was on xs 6, so downgraded to xs 5), and nothing seems to work, other than uninstalling the app.

Its getting so annoying and doesn't help productivity. Please help me out.

Social Logins

$
0
0

Have any of you guys set up sharing with Facebook, Twitter, etc.? I'm curious how you guys go about verifying accounts. The SDK I've seen for Facebook is platform specific, and VS doesn't seem to like non-.cs files. I've seen some other SDKs that look outdated.

Maybe I missed something, as I've really only done some preliminary work on it. Just curious how you guys have done it, how successful it's been, and if there are specific resources you'd recommend.

Thanks

In-app Purchases

$
0
0

Is there a recommended/best practice through Xamarin.Forms to set up in-app purchases? Haven't started yet, but I'm a little hesitant on getting that piece started. Any help/pointers/suggestions would be appreciated!

Thanks


In-app Purchases

$
0
0

Is there a recommended/best practice through Xamarin.Forms to set up in-app purchases? Haven't started yet, but I'm a little hesitant on getting that piece started. Any help/pointers/suggestions would be appreciated!

Thanks

Memory management in Xamarin forms (Low memory warnings)

$
0
0

I am unable to find any documentation on how Xamarin Forms handles low memory warnings from the platforms.

Are the pages and views being deallocated to free memory?
Is there any mechanism in place to recreate pages and views if they are deallocated?
Is any of this documented?

Cheers!

Binding Multiple Custom Property in a Custom View using Xamarin.Forms

$
0
0

Hi,

I am working on creating the User control to use in multiple content pages with Xamarin.Forms.

As mentioned in the Binding a Custom View In Xamarin.Forms we have defined the Custom Binding properties for Custom view.

When we have a single Custom property , the custom view fires up the property (get,set) and assigns the vales. But when we have multiple Custom Properties the Properties(get,set) are not fired up.

Please find the Sample code here
Kindly help me to resolve the issue.

Thanks you very much for your support.

Best Regards,
Kathirvelu M

SlideOverKit - Set up in XAML and how to slide menu from PageModel?

$
0
0

@MichaelRidland I'm using SlideOverKit for my menus, but can't see how to:

  1. Specify the SlideMenuView to display in my XAML (all the samples set this up from code behind)
  2. Slide the menu from my PageModel. Again, the samples show this being done from a simple Page from its code behind, rather than a Page with a PageModel.

I'm using FreshMVVM for my MVVM implementation, if that helps.

How to center a Label in RelativeLayout in xaml?

Viewing all 91519 articles
Browse latest View live


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