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

Xamarin Label not updating after initial in Mvvm listview

$
0
0

I have 2 listviews in my page. First list shows categories horizontally. Second list shows corresponding products below upon clicking category. Each list item of second list contains plus and minus buttons to add product to the cart. Label updates the count of each product upon clicking buttons.Works perfect for the first time. label is not updating in ui after coming from other category.Button clicks are working, While debugging, label value is updated correctly in viewmodel but not reflected in ui since second time.Need help..

<ListView  x:Name="pdt_list" HasUnevenRows="True" SeparatorVisibility="None" ItemsSource="{Binding Productlist}" BackgroundColor="White" Margin="0,10,0,0" >
            <ListView.ItemTemplate>
                <DataTemplate >
                    <ViewCell >
                        <ViewCell.View>
                             <Frame HasShadow="False" Margin=" 0,10,0,10"  Padding="10,5,10,5" BackgroundColor="#e9e9e9" HeightRequest="80" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" >
                                  <Grid>
                                            <!--<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand"  Margin="0,10,0,10"  >-->

                                  <StackLayout VerticalOptions="FillAndExpand" Margin="0" Padding="10,0,0,0" Orientation="Horizontal" Opacity="{Binding opacity}">

                                     <Image Source="{Binding image}"  Aspect="AspectFill"  WidthRequest="70" HeightRequest="180"  VerticalOptions="FillAndExpand" />

                                      <StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical"  >

                                        <Label Text="{Binding product_name}" Font="Bold" VerticalTextAlignment="Center" FontSize="Medium" TextColor="Black" FontFamily="opensans_light.ttf#opensans_light" Margin="10,20,0,0" />
                                            <StackLayout Orientation="Horizontal" Margin="10,0,0,0" HorizontalOptions="Start" VerticalOptions="Start"  >
                                                        <Label Text="{Binding rupee}"  TextColor="#FA2E27" HeightRequest="90" 
                                                            FontSize="Medium" HorizontalOptions="Start" VerticalTextAlignment="Start" VerticalOptions="FillAndExpand" />
                                                        <Label Text="{Binding selling_price}" Font="Bold"  HorizontalOptions="Start" Margin="0" TextColor="#FA2E27" VerticalTextAlignment="Start" FontSize="Medium" FontFamily="opensans_light.ttf#opensans_light" />

                                           </StackLayout>
                                      </StackLayout>
                                      <ImageButton Source="carts.png" BackgroundColor="Transparent" IsVisible="False" HorizontalOptions="EndAndExpand" WidthRequest="40" HeightRequest="40" VerticalOptions="CenterAndExpand"  Clicked="Add_cart_Clicked" Margin="0,20,0,0" Aspect="AspectFit" />


                                    <StackLayout Orientation="Horizontal" BackgroundColor="Transparent"   HorizontalOptions="EndAndExpand">
                                        <ImageButton Source="minus.png" HorizontalOptions="EndAndExpand"   BackgroundColor="Transparent"  WidthRequest="25" HeightRequest="25" Clicked="Minus_Tapped" />
  //this label is not updating          <Label Text="{Binding Num}" VerticalTextAlignment="Center" HorizontalOptions="EndAndExpand"   FontSize="Medium" TextColor="Black" FontFamily="opensans_light.ttf#opensans_light" Margin="0,0,0,0" /> 
                                        <ImageButton Source="plus2.png" HorizontalOptions="EndAndExpand"   BackgroundColor="Transparent"   WidthRequest="25" HeightRequest="25"  Clicked="Plus_Tapped"   />
                                    </StackLayout>
                                            </StackLayout>

                                            <StackLayout BackgroundColor="Black" HorizontalOptions="EndAndExpand" VerticalOptions="StartAndExpand" WidthRequest="100" HeightRequest="25" IsVisible="{Binding opaque}" Margin="0,0,0,0" >

                                                <Label Text="Not Available" FontFamily="opensans_light.ttf#opensans_light" TextColor="White" FontAttributes="Bold" HorizontalOptions="Center" VerticalTextAlignment="Center" />
                                            </StackLayout>
                                  </Grid>
                             </Frame>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

viewmodel:

After clicking plus button, this code is executed:

public ObservableCollection<Product_Value2> purchaselist = new ObservableCollection<Product_Value2>();

public void Plus_item(Product_Value2 product_Value2)
    {
        var list = new ObservableCollection<Product_Value2>(purchaselist);


        string id = product_Value2.id;
        ProductsRegister reg = new ProductsRegister();

        reg.Name_Product = product_Value2.product_name;
        App.Database.SaveProducts(reg);



        if ((purchaselist.ToList() != null) && (purchaselist.ToList().Any()))
        {
            //  bool alreadyExists = purchaselist.Any(x => x.id.Equals(id));
            if (purchaselist.Any(x => x.id.Equals(id)))
            {
                foreach (Product_Value2 pdt in list)
                {
                    if (pdt.id.Equals(id))
                    {
                        pdt.Num++; // here value is updating everytime,but first time only in ui
                OnPropertyChanged("Num");

                    }

                }
            }



        }



        DependencyService.Get<IToast>().ShortAlert("Added To Cart");

        Number++;
        OnPropertyChanged("Number");

    }

Model:

public class Product_Value2 : INotifyPropertyChanged
    {         
        public string id { get; set; }
        public string image { get; set; }
        public string imagepath { get; set; }
        public string product_name { get; set; }
        public string rupee { get; set; }
        public float selling_price { get; set; }
        public float price { get; set; }
        public string available_qty { get; set; }
        public string count { get; set; }        
        public bool minus_enb { get; set; }
        public bool plus_enb { get; set; }


        bool Visibility;
        public bool visibility
        {
            set
            {
                Visibility = value;
                OnPropertyChanged("visibility");
            }
            get
            {
                return Visibility;
            }
        }

        long num1 ;
        public long Num  //this is the label text
        {
            set
            {
                num1 = value;
                OnPropertyChanged("Num");
            }
            get
            {
                return num1;
            }
        }


        bool Visible;
        public bool visible
        {
            set
            {
                Visible = value;
                OnPropertyChanged("visible");
            }
            get
            {
                return Visible;
            }
        }




        void OnPropertyChanged(string IsVisible)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(IsVisible));
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }

Attaching the screenshot below: first time;

second time;


How can I change the Detail Title section?

$
0
0

I have a Xamarin Forms application, and the only plaftorm it supports is UWP. I use Master-Detail architecture. I understand how I can change the Title text of the Detail page, but I need to change e.g. height of the Title pane and its background color. I guess it should be done on the MySolution.UWP project, but don't know how to approach this. I don't even know what I should change, TopCommandBarArea, or CommandBar, or LayoutRoot etc.

Here is some of my code from the shared project:

    private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        var item = e.SelectedItem as MainMDPageMenuItem;
        if (item == null)
            return;

        item.ItemBackgroundColor = Color.FromHex("#006c89");
        if (PreviouslySelectedItem != null)
        {
            PreviouslySelectedItem.ItemBackgroundColor = Color.FromHex("#00a8d5");
        }

        var page = (Page)Activator.CreateInstance(item.TargetType);
        page.Title = item.Title;

        Detail = new NavigationPage(page);
        IsPresented = false;

        MasterPage.ListView.SelectedItem = null;

        PreviouslySelectedItem = item;
    }

Here is how it looks. The area in question has a red border around it:

Issue while opening Xamarin form from BroadcastReciever class

$
0
0

This is for tracking incoming and outgoing phone calls. I am pushing a Xamarin form in the application Navigation stack from BroadcastReciever class using following code:

var phoneAddPage = new SomePage();
Xamarin.Forms.Application.Current.MainPage = new NavigationPage(phoneAddPage);

The page is getting pushed properly as expected. Issue is the page is overlapped by Splash Screen when application is opened. The form is functioning properly, overlap is the only issue.

Label.XAlign vs HorizontalOptions

$
0
0

Can someone advise on best practices for when to use Label.XAlign and when to use HorizontalOptions? It seems that both can achieve the same results in many cases, but I'd like to know if I'm overlooking something.

Same question also for YAlign vs VerticalOptions if the answer is different.

When we Opening the Gallery from App.The design of the screen and Text changed to different

$
0
0

When we Opening the Gallery from App.The design of the screen and Text changed to different Positions.
how to solve the problem if any please suggest.

it will come correctly when close the page and after re open

Background color of "ActionBar"/"Toolbar v7" with FormsAppCompatActivity

$
0
0

Hi there,

I finally figured out I should migrate from FormsApplicationActivity to FormsAppCompatActivity. After doing that and adapting a few configuration options here and there, my theme is now as follows:

  <style name="CustomTheme" parent="CustomTheme.Base">
  </style>

  <style name="CustomTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <!-- We will be using the toolbar so no need to show ActionBar -->
    <item name="windowActionBar">false</item>

    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/primary</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">@color/accent</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <!--item name="colorControlHighlight">@color/primary_light</item-->
    <!--item name="colorControlActivated">@color/primary_light</item-->
    <!--item name="colorLongPressedHighlight">@color/listitem_longpressed</item-->
  </style>

That's dumb but I don't figure out how to get back a dark actionbar:

It does not look dark at all, since it's white background with black text...

Select text in label and copy it

$
0
0

In Xamarin Forms when I am creating a label I cannot select it and copy. How can I make a label in Xamarin Forms copyable? Currently, for me its strange behavior that user is not able to select and copy text in my application.

Reducing the size of a fixed header while scrolling a TableView

$
0
0

Hi there,

I've updated my app so that "profile pages" look more appealing. I inspired from a Xamarin University video https://www.youtube.com/watch?time_continue=2&v=4HlLjTZQzjM and implemented something like that (screenshot from the video and custom overlay):

Now, my question is how could I possibly "detect" the scrolling of the TableView so that I could reduce the size of the fixed header? Goal is something similar to that: https://www.w3schools.com/howto/howto_js_shrink_header_scroll.asp

The underlying layout is a grid with 3-4 rows, the last one being the container for the TableView.

I'm targeting both iOS and Android.

Thanks


Splash Screen on iOS

$
0
0

I'm trying to setup a splash screen for iOS. Its suppose to be simple enough, however I have an issue inserting an image. When I went through the documentation, there was an example of simply selecting an image from drop down menu, but when I press on the drop down menu, a new window opens asking to Add Existing Item. After selecting an image I want to insert, nothing happens. I have my image saved in the Resources folder and I also have it in the Asset Catalog.

Icon moves after clicking on its adjacent icon

$
0
0

one of my footer icon on dashboard page moves a bit left after clicking on another icon

jarsigner error java.lang.runtimeexception keystore load keystore was tampered with, or password wa

$
0
0

Getting the title error when publishing android APK in Xamarin Forms. I am trying to do this from Mac visual studio.

Screenshot:

I am sure my password is correct. Is there any other reason for this issue? What is keystore tampering?

Please help me.

Custom Stepper with 2 buttons and Entry

$
0
0

Hi ,
I used stepper but since i couldn't change it's seize now I have to replace it by 2 buttons .

Is there any sample like that ? working just like stepper ?

ListView binding to ObservableCollection does not update GUI

$
0
0

Hi

Can anyone tell me why this simple code is not working as expected? Does the ListView control not listen for changes in the bound property?

  • Expected: when I click the Add button, the GUI (ListView) updates through the binding and shows the new element in the ObservableCollection.
  • Observed: GUI does not update but always shows the initial three items of the ObservableCollection.
  • Btw: OnAddButtonClicked() does get called and ListViewItems does get updated (checked in the debugger). Calling OnPropertyChanged("ListViewItems") inside OnAddButtonClicked() did not help either.
  • And: if I update the code as follows, the ListView works: add a Label control, bind that label to a 2nd property, update that property inside OnAddButtonClicked(), call OnPropertyChanged() from inside the property setter. So obviously this call to OnPropertyChanged() somehow triggers the ListView to get updated as well...
  • I'm now using Xamarin.Forms version 1.1.0.6201. Didn't work with the previous version either.

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="Test1.MainPage"
             Padding="10" Title="MainPageXaml">
    <StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="Fill">
        <Button Text="Add" Clicked="OnAddButtonClicked" />
        <ListView ItemsSource="{Binding ListViewItems}" />
    </StackLayout>
</ContentPage>

C#:

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        ListViewItems = new ObservableCollection<string> { "one", "two", "three" };
        BindingContext = this;
    }

    private void OnAddButtonClicked(object sender, EventArgs e)
    {
        ListViewItems.Add(DateTime.Now.ToString());
        // OnPropertyChanged("ListViewItems");
    }

    public ObservableCollection<string> ListViewItems { get; set; }
}

Markus

How to get rid of Hamburger icon

$
0
0

I have been revisiting one of my old Xamarin apps and I noticed the hamburger icon appear on the bottom navigation bar.

Does anyone know how to get rid of this?

How to disable Home button click on some page in Xamarin.Forms

$
0
0

Hi,

Is there a way to disable home button click on particular page in xamarin forms.

Thanks.


My app command bar changed its color for no good reason

$
0
0

A strange thing happened to my application. The main window command bar (the one with minimize and maximize buttons) from common gray became black. The buttons stayed gray. I don't think I did anything to cause this.
Could you please give me any idea what did this and how to change this back?

What is the best way to design in Xamarin

$
0
0

I need to design Xamarin app screen. What is the best way for this. Any Suggestions Please

Xamarin form :How to search in listview

$
0
0

I have listview in which data coming from web api, i want to search in listview with character wise, the problem i am facing when is start searching its working fine but its getting very very slow need some solution to fix it. Here is my code

        private async  void Entry_TextChanged(object sender, TextChangedEventArgs e)
        {

                        var httpClient = new HttpClient();


                        var json = await httpClient.GetStringAsync(" http://172.16.4.212:51583/api/GetItems");


                        var admtPatients = JsonConvert.DeserializeObject<List<tblItem>>(json);
                        ObservableCollection<tblItem> trends = new ObservableCollection<tblItem>(admtPatients);
                        if (string.IsNullOrEmpty(medicine.Text))
                        {
                            MyListView.ItemsSource = trends;
                        }
                        else
                        {
                            MyListView.ItemsSource = trends. Where(x => x.strItemName.ToLowerInvariant().Contains(e.NewTextValue.ToLowerInvariant()) || x.strItemName.ToUpperInvariant().Contains(e.NewTextValue.ToUpperInvariant()));
                        }

                        //await ((MainViewModel)this.BindingContext).LoadCountNotificationAsync();

            }

Hide a specific child page of a CarouselPage

$
0
0

Hi Guys,

I need a way to hide a specific carousel page. I do not want to remove the page as a whole because then I would lose all the changes made on that particular page which I want to maintain like Field changes, Scroll position, control states and so on. Possible? I dont mind using TabbedPage is this feature is only possible on that.

Thanks.

How to Use PullToRefreshLayout control in StackLayout in Xamarin.Forms ?

Viewing all 91519 articles
Browse latest View live