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

Trouble with XAML and data binding

$
0
0

Hello, I'm making a very simple app with Xamarin forms where I've products with a quantity for each one. Everything is saved in a database:

[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string Name { get; set; }
public int Quantity { get; set; }

From a ListView I select my product, and I want to get its informations, Name and Quantity. No problem so far. Then I have a Stepper to increment this quantity, but pressing on it, nothing change from my Quantity.
My XAML:

<?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="ProductXAML" Title="Product">

    <StackLayout VerticalOptions ="FillAndExpand">

        <StackLayout Orientation="Horizontal">
            <Label Text="Name :" />
            <Label Text="{Binding Name}" />
        </StackLayout>

        <StackLayout Orientation="Horizontal">
            <Label Text="Quantity :" />
            <Label Text="{Binding Quantity}" />
            <Stepper Minimum="0" Increment="1" ValueChanged="OnQuantityChanged" Value="{Binding Quantity}" />
        </StackLayout>

    </StackLayout>

</ContentPage>

And now the C#

public partial class ProductXAML : ContentPage, INotifyPropertyChanged {

    public event PropertyChangedEventHandler PropertyChanged;

    StockItem _stockItem;

    public ProductXAML (StockItem stockItem)
    {
        _stockItem = stockItem;
        BindingContext = _stockItem;

        InitializeComponent ();
    }

    void OnQuantityChanged(object sender, ValueChangedEventArgs e) {

        _stockItem.Quantity = (int)e.NewValue;

        Debug.WriteLine (e.NewValue);

        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs("Quantity"));
    }
}

Also I've this warning, not sure how to resolve it: `ProductXAML.PropertyChanged hides inherited member Xamarin.Forms.BindableObject.PropertyChanged. Use the new keyword if hiding was intended (CS0108)

Thanks for your help!


xamarin Http client

$
0
0

Hello,
please how to get the Json using an http client with c# in xamarin forms and which authorization is required to do it

Stack Overflow when using Tabbed pages

$
0
0

Hi

I'm using a TabbedPage root with 6 ContentPage sub-classes. Running the app on iPhone 4s IOS 8.1 simulator, I find selecting one of the tabs via the tab control at the bottom is fine. Likewise, selecting the two tabs that are available in the "More" bit is fine. However, when using the in-built ability to move one of the tabs in the more section to the bottom bar, the following stack overflow exception is throw when selecting anything in the tab navigation bar.

cheers

Seyed

System.StackOverflowException: The requested operation caused a stack overflow.
at at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr (intptr,intptr,intptr)
at UIKit.UITabBarController.set_SelectedViewController (UIKit.UIViewController value) [0x00041] in /Developer/MonoTouch/Source/monotouch/src/build/native/UIKit/UITabBarController.g.cs:246
at Xamarin.Forms.Platform.iOS.TabbedRenderer.set_SelectedViewController (UIKit.UIViewController value) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00000] in :0
at at (wrapper delegate-invoke) :invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in :0
at Xamarin.Forms.MultiPage

1[Xamarin.Forms.Page].OnPropertyChanged (System.String propertyName) [0x00000] in <filename unknown>:0
  at Xamarin.Forms.MultiPage
1[Xamarin.Forms.Page].set_CurrentPage (Xamarin.Forms.Page value) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.UpdateCurrentPage () [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.set_SelectedViewController (UIKit.UIViewController value) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00000] in :0
at at (wrapper delegate-invoke) :invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in :0
at Xamarin.Forms.MultiPage
1[Xamarin.Forms.Page].OnPropertyChanged (System.String propertyName) [0x00000] in <filename unknown>:0
  at Xamarin.Forms.MultiPage
1[Xamarin.Forms.Page].set_CurrentPage (Xamarin.Forms.Page value) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.UpdateCurrentPage () [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.set_SelectedViewController (UIKit.UIViewController value) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00000] in :0
at at (wrapper delegate-invoke) :invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in :0
at Xamarin.Forms.MultiPage
1[Xamarin.Forms.Page].OnPropertyChanged (System.String propertyName) [0x00000] in <filename unknown>:0
  at Xamarin.Forms.MultiPage
1[Xamarin.Forms.Page].set_CurrentPage (Xamarin.Forms.Page value) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.UpdateCurrentPage () [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.set_SelectedViewController (UIKit.UIViewController value) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.TabbedRenderer.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00000] in :0
at at (wrapper delegate-invoke) :invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.

How to use component on forms?

$
0
0

I got a component from Xamarin's component store and It's available to Android and iOS...

How can I use this component on shared/portable project (forms)?
Or can I join a forms content with a ViewController? I can't understand this :X
I see something called "wrapper" but I don't remember where and I can't find it anymore!

Is the Microsoft Visual Studio XAML Designer supported for PCL XAML files?

$
0
0

Is the Microsoft Visual Studio XAML Designer supported for PCL XAML files? If I create a new XAML Content Page in a PCL App Project, the Designer fails to load with an exception. The markup view works, and the application works.

Using latest stable Xamarin on latest Windows 7 and latest Visual Studio.

Using Xaml and get "Additional information: An item with the same key has already been added."

$
0
0

I have the following Xaml:

<ContentPage.Content>
    <ScrollView>
      <ListView ItemsSource="{Binding GroupedItems}" IsGroupingEnabled="true" GroupDisplayBinding="{ Binding Name }" GroupShortNameBinding="{ Binding ShortName }" IsEnabled="False">
        <ListView.ItemTemplate>
          <DataTemplate>
            <TextCell  Text="{Binding Title}" Detail="{Binding Text}" IsEnabled="False"></TextCell>
            <Grid HorizontalOptions="CenterAndExpand">
              <Image></Image>
              <Image></Image>
              <Image></Image>
              <Image></Image>
              <Image></Image>
            </Grid>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
    </ScrollView>
  </ContentPage.Content>

I keep getting the following exception:

_An exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: An item with the same key has already been added._

What is it referring to? I have had this on a number of occasions but not sure what rules I'm breaking...

Why Account.Properties from Xamarin.Auth has private set?

$
0
0

Hi,
Is there any way to store user credentials using Xamarin.Auth and Account class or I have to use some third party library like Akavache?
Best,
TK

I've got "The item you were attempting to purchase could not be found" after publishing a new app

$
0
0

Hi. I've created a new app with Xam Forms. Everything worked well, but after publishing it I've got "The item you were attempting to purchase could not be found" when I wanted to buy it from Google Play. I've builded it with Xamarin Studio and signed it as Guide says.
What should I do to make it work?


Optimizing OnSizeAllocated and layout of elements

$
0
0

Are there any guidelines/recommendations about optimizing OnSizeAllocated and the layout process in general?

I have just been investigating recursion in OnSizeAllocated and putting in some optimizations, but it would be useful to know if there is any guidance about how best to do things such as re-sizing or re-positioning elements on a page based on the allocated page size, where “best” means safely, speedily and without using excessive memory.

Many thanks,

John H.

Are there any productively used apps out which uses Xamarin.Forms?

$
0
0

I'm currently evaluating Xamarin.Forms. As I can see the main issue is that through the standardisation of the UI you loose the plattform specific look and feel and it goes in the direction of PhoneGap apps or similar. On the other side you can write very fast code for all three plattforms. In my mind Xamarin.Forms seems to be suitable only for "simple" apps. Or am I wrong? If you try plattform specific adaptions it gets complicated and your time savings are gone.

So I want to find the advantages and disadvantages of Xamarin.Forms ... If you start once with Xamarin.Forms you stick with Xamarin.Forms. Currently, I don't see how you go back to use view controllers (iOS) and only sometimes use Xamarin.Forms for some screens. Furthermore, I read about performance issues. Is this strill true? A short test on an iPhone 4 brought an increased start up time (6 vs. 8 seconds). If you take into account that the Xamarin.Forms apps was very simple and the Xamarin.iOS app more complex this is a difference!

Is there a documentation out there which explains the Xamarin XAML dialect?

To come back to my main question: Are there any released apps out, which already uses Xamarin.Forms? Then I would get more insight about performance issues and what is possible.

XForms Banking App - Success Story

Android Master Detail - area "behind" master is dimmed out, but still active

$
0
0

We're using MasterDetailPage to provide a flyout menu in our app. In iOS, the master pushes the detail out of the way. On Android, the Master appears on top of the detail, and the visible portion of the detail is greyed out.

However, even though the detail is greyed out and appears inactive, it still responds to touches. So if users inadvertently tap on the background instead of the menu, the menu dismisses and they are confused about what happened.

Is there any way to disable or control this behavior?

Wcf webservice using proxy

$
0
0

Hello,

I successfully setup a Wcf proxy for use in my Xamarin project. Now I can call the web service functions like in the official guide(http://developer.xamarin.com/guides/cross-platform/application_fundamentals/web_services/walkthrough_working_with_WCF/).

My question is: should I create a soap client(the class generated by the proxy) in every ViewModel where I wish to use it or simply use the same instance application-wide?
Creating an instance on every page where it is needed seems easier to manage, but is it a good thing to create more than one instance of the client?
I'm new to using webservices.

Thanks!

Xamarin apps running very slow.

$
0
0

Hi,

We have speed issues in Android version 4.1.2. The application works fine in later versions of Android, but it is painfully slow in 4.1.2. The issue that we face is, it takes about 10 seconds to redirect from the login page to the home page. It takes about 3 seconds in other versions. Our client has a mobile device and a tablet, both with version 4.1.2. We have the latest version of XF(1.3.4).

Below is our build configuration: -

Release Mode
Linking : Sdk Assemble only (We tried set it to "Sdk and User assemblies" but it gives an error. Any solution/reason for this?)

Is this a known issue?
Is there any workaround for this?

It is getting difficult for us to explain our client and are running out of time and reasons.

Thanking you in advance.

Clicked vs Command

$
0
0

Is there any difference between using Clicked or Command on a Cell/Button?


SQLite Android : All data are removed sometimes after rebuilding.

$
0
0

Hello ,
I found out that when I rebuild a solution and run it on an emulator or real device , all my stored data are removed, I suspect that the db3 file is recreated again.
I would like that my data to be more persistent . How to do that ? I use this statement to save the file string
documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
So how can I find the file itself by the way ?

ListView ItemTapped issue on Windows Phone

$
0
0

Hi,

we encounter an issue ItemTapped event of ListView on Windows Phone, still with 1.3-pre3.
The event doesn't fire if tapping two times on the same item: basically on WP behaves as ItemSelected event. Different behavior for instance on Android.

This can be easily reproduced in a XF App with following MainPage markup

`

<Grid>

 <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>

<Grid.RowDefinitions>
  <RowDefinition Height="*" />
  <RowDefinition Height="100" />
</Grid.RowDefinitions>
<ListView x:Name="MyListView"
            RowHeight="80"
            ItemsSource="{Binding }">
  <ListView.ItemTemplate>
    <DataTemplate>
      <ViewCell>
        <ViewCell.View>
          <Label Text="{Binding }"
                 TextColor="Green"
                 Font="28" />
        </ViewCell.View>
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>
<Label Grid.Row="1" x:Name="LogLabel" Font="28" Text="XXX" TextColor="Red" />
</Grid>

`

and following code behind:

`

   public ObservableCollection<string> Items { get; set; }
    private int _counter = 0;

    public MainPage()
    {
        this.Items = new ObservableCollection<string>();
        InitializeComponent();

        this.BindingContext = this.Items;
        MyListView.ItemTapped += (sender, e) =>
        {
            LogLabel.Text = string.Format("{0} - Item {1} Tapped!", _counter++, (string)e.Item);
        };

    }

    protected override void OnAppearing()
    {
        this.Items.Add("First");
        this.Items.Add("Second");
        this.Items.Add("Third");
        base.OnAppearing();
    }

`

Running on Androind and WP, you will notice two different behaviors.
This issue was already in 1.3-pre1 (I don't know before), and still in 1.3-pre3.

Link native assembly

$
0
0

How can I link a native assembly to a Forms project and them consume it with c#?

Blank App(Xamarin.Forms Portable) not creating windows phone project

$
0
0

When i create Xamarin.Forms Portable app its not creating winodws phone 8 project :(

I using :
1) VS professional 2013 + update 4
2) Winodws phone 8 SDK is installed
3) Xamarin 3.9.236.0

Custom ListAdapter

$
0
0

Hi,

New to Xamarin and have a question on building a custom list adapter.

I have an ImageButton in my ListAdapter that instantiates a .Click event to show or hide more information.
Issue is that when I have more records than can be displayed on the phone and scroll it sometimes registers the .click event more than once.
It also registers the .click event more than once if I leave that layout page and go back to it.
This causes the more Information to be expanded/collapsed with a single click.

Any help would be appreciated.

Erik

Here is my ListAdapter Code Snippet;

    public ListLayoutAdapter (Activity context, List<ListLayout>items)
    {
        usedPos = new List<int>();
        this.context = context;
        this.items = items;
    }

    public override View GetView(int position, View convertView, ViewGroup parent) 
    {
        var item = items [position];
        View view = convertView;
        if (view == null) 
        {
            view = context.LayoutInflater.Inflate (Resource.Layout.ListViewTemplate, null);
        }
        // Get controls
        ImageView btImgView1 = view.FindViewById<ImageView> (Resource.Id.imgView1);
        TextView txtListMeter = view.FindViewById<TextView> (Resource.Id.txtListMeter);
        TextView txtAction = view.FindViewById<TextView> (Resource.Id.txtAction);
        TextView txtDate = view.FindViewById<TextView> (Resource.Id.txtDate);
        TextView txtMoreInfo = view.FindViewById<TextView> (Resource.Id.txtMoreInfo);
        ImageButton btMoreInfo = view.FindViewById<ImageButton> (Resource.Id.btMoreInfo);
        // Set the columns in the Listview
        btImgView1.SetImageResource (item._listIcon);
        txtListMeter.Text = item._listMeter;
        txtAction.Text = item._listAction;
        //
        // Set color of the action
        //
        if (item._listAction == RDM.Globals.MeterActions.Connect.ToString()) {
            txtAction.SetTextColor (Android.Graphics.Color.Green);
        }
        else if (item._listAction == RDM.Globals.MeterActions.Disconnect.ToString())
        {
            txtAction.SetTextColor (Android.Graphics.Color.Red);
        }
        else
        {
            txtAction.SetTextColor (Android.Graphics.Color.Rgb (49, 93, 116));
        }
        txtDate.Text = item._curDate;
        txtMoreInfo.Text = item._moreInfo;
        //
        btMoreInfo.Focusable = false;
        btMoreInfo.FocusableInTouchMode = false;
        btMoreInfo.Clickable = true;
        //
        // Make all the columns of the listview rows clickable to expand/collapse
        // 
        if (item._listAction == string.Empty )
            btMoreInfo.Visibility = ViewStates.Invisible;
        if (!usedPos.Contains (position) && item._listAction !=string.Empty) 
        {
            Console.WriteLine ("ListLayout Postion: " + position.ToString ());
            usedPos.Add (position);
            btMoreInfo.Click += (object sender, EventArgs e) => {
                view.FindViewById<TextView> (Resource.Id.txtMoreInfo).Visibility = 
                (view.FindViewById<TextView> (Resource.Id.txtMoreInfo).Visibility == ViewStates.Visible ? ViewStates.Gone : ViewStates.Visible);
                if(view.FindViewById<TextView> (Resource.Id.txtMoreInfo).Visibility == ViewStates.Visible)
                {
                  view.FindViewById<ImageView>(Resource.Id.btMoreInfo).SetBackgroundResource(Resource.Drawable.up);
                }
                else
                {
                    view.FindViewById<ImageView>(Resource.Id.btMoreInfo).SetBackgroundResource(Resource.Drawable.down);
                }
            };
        }

        return view;
    }

Page that has ListView Template snippet:

...
...
...
...
...
... <TextView...
... android:text="Medium Text"
... android:textAppearance="?android:attr/textAppearanceMedium"
... android:layout_width="255dp"
... android:layout_height="30dp"
... android:layout_below="@id/txtListMeter"
... android:layout_toRightOf="@id/imgView1"
... android:gravity="left"
... android:id="@+id/txtAction" />
...
...
...
...

Page that displays the Listview

...
...
...
...
...
...
...
...
...

Viewing all 52968 articles
Browse latest View live


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