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

Grouped ListView not binding delete Command using MVVM

$
0
0

Hi everyone,
I'm getting crazy trying to bind a Command in order to remove an item from a grouped ListView.
My ViewModels inherit from a BaseViewModel in order to ease the notification of a changing property.
I followed the common approach that seems to be the correct one by using two ObservableCollections.

Those are my ViewModels, that are displayed correctly, but I cannot bind the RemoveCommand to each item (of type ArticleForOrdineOTIVM). I used the constructor for creating dummy objects.
I tried every sort of combination in my xaml file within Command="", for example by pointing Source reference to the listview name, but I can't make it work. It always says like i cannot reach the scope of the inner Context, but at most I can bind a command within OrderOTIVM, no further (for example the Command "TestCommand"). I need to do this because I want to remove, edit and do stuff inside each item of the list, and the error explained before says:

Binding: 'RemoveCommand' property not found on 'System.Collections.ObjectModel.ObservableCollection`1[BrScanner.ViewModels.GroupedArticlesVM]', target property: 'Xamarin.Forms.Button.Command'

In the View file I set the BindingContext as:

public partial class OrderOTIView : ContentPage
    {
        public OrderOTIView()
        {
                InitializeComponent();
        OrderOTIVM orderOTIViewModel = new OrderOTIVM();
            BindingContext = orderOTIViewModel;
        }
    }

These are my ViewModels:

public class OrderOTIVM : BaseViewModel
    {
        ObservableCollection<GroupedArticlesVM> _carrelliGrouped;
        public ObservableCollection<GroupedArticlesVM> CarrelliGrouped { get => _carrelliGrouped; set {  _carrelliGrouped = value; OnPropertyChanged();}
        }

        public OrderOTIVM()
        {
            CarrelliGrouped = new ObservableCollection<GroupedArticlesVM>();
            GroupedArticlesVM car1 = new GroupedArticlesVM();
            car1.Carrello.Nome = "Carrello A";
            CarrelliGrouped.Add(car1);

            GroupedArticlesVM car2 = new GroupedArticlesVM();
            car2.Carrello.Nome = "Carrello B";
            CarrelliGrouped.Add(car2);

        }
    public Command TestCommand
            {
                get
                {
                    return new Command(
                        (x) => {
                            Debug.WriteLine("TestCommand");
                        });
                }
            }
    }

    public class GroupedArticlesVM :  ObservableCollection<ArticleForOrdineOTIVM>
    {
        CarrelloMinimarketVM _carrello;
        public CarrelloMinimarketVM Carrello { get => _carrello; set { _carrello = value; } }

        public GroupedArticlesVM()
        {
            Items.Add(new ArticleForOrdineOTIVM());
            Items.Add(new ArticleForOrdineOTIVM());
            Items.Add(new ArticleForOrdineOTIVM());
            Items.Add(new ArticleForOrdineOTIVM());

            Carrello = new CarrelloMinimarketVM();
        }


        public Command<ArticleForOrdineOTIVM> RemoveCommand
        {
            get
            {
                return new Command<ArticleForOrdineOTIVM>(
                    (articolo)=>{
                        Items.Remove(articolo);
                });
            }
        }

    }

    public class CarrelloMinimarketVM : BaseViewModel
    {
        string _nome;

        public CarrelloMinimarketVM()
        {
            this.Nome = "CARRELLO";
        }

        public string Nome { get => _nome; set { _nome = value; OnPropertyChanged(); } }
    }

    public class ArticleForOrdineOTIVM : BaseViewModel
    {
        string _oarti;
        string _tarti;
        int _amount;

        public string Oarti { get => _oarti;    set {   _oarti = value;     OnPropertyChanged(); } }
        public string Tarti { get => _tarti;    set {   _tarti = value;     OnPropertyChanged(); } }
        public int Amount { get => _amount;     set {   _amount = value;    OnPropertyChanged(); } }

        public ArticleForOrdineOTIVM()
        {
            this.Oarti = "Oarti blabla";
            this.Tarti = "Descrizione blabla";
            this.Amount = 22;
        }  
    }

This is my Xaml code:

<?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:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="BrScanner.Views.OrderOTIView"
             x:Name="OrderOTIPage"
             >
            <ListView x:Name="carrelliListView" ItemsSource="{Binding CarrelliGrouped}"
                      HasUnevenRows="True"
                      GroupDisplayBinding="{Binding Carrello.Nome}"
                      IsGroupingEnabled="True">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal" Padding="10">
                                <Label Text="{Binding Oarti}"/>
                                <Label Text="{Binding Tarti}"/>
                                <Button Text="cancella" 

                                        Command="{Binding Path=BindingContext.CarrelliGrouped.RemoveCommand, Source={x:Reference Name=OrderOTIPage}}"
                                        CommandParameter="{Binding .}"/>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

My BaseViewModel:

public class BaseViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

Thanks for your time!


Xamarin Forms: How to capture the time spend on a page

$
0
0

I need to capture the time a user spends on a page in my application.

I wish the time is in hour: minutes: seconds.

Using this I can track the user activities. I do some research but didn't found anything useful.

Is there any way to track the time a user spends on a page?

Working with Xamarin.forms and remote procedure calls

$
0
0

I’m having problems with a Xamarin forms project. This project contains an Android, IOS, and UWP projects.

I’m trying to create an azure based remote procedure call application for my Xamarin application to use in passing images and other data to work against an azure databases.
I have tried the following:
WCF (with asmx) – works with the UWP but not with android or IOS
WFC (creating as .svc file) – doesn’t work at all
gRPC – now working with Xamarin at all.
I’ve been working on this problem for nearly a month and an no closer to making this work than when I started.
Can you help? Do you have Xamarin forms code that move images back and forth between a mobile app and service hosted on azure?
!!!HELP!!!
Frustrated and Excused

Setting the background of a MasterDetailPage to be transparent

$
0
0

When I try to set the background color of the Master (of the MasterDetailPage) to transparent, it stays white.

Basically what I would want to see, is that the color from the detail page is shown through the Master.

FOR EXAMPLE (If the above were true, then the background color of this MasterDetailPage would be red (Yes I know I can just set the background colour as red, but I want it to be transparent))

RadioButton in a ListView Problem

$
0
0

I am running into a bit of an issue when implementing the new experimental RadioButton in a ListView. The radio buttons work great until I start scrolling though the list. After selecting a few options for each radio group in the beginning of the list, then scrolling to the bottom, they become non responsive, and seem to have the same values selected as the one at the top of the list. It's almost like it's sharing/conflicting with other radio button elements in the list.

I have added some quick and dirty code below to demonstrate the issue.

public class MainPage : ContentPage
    {
        public MainPage()
        {
            int numberOfRows = 10;
            List<object> objList = new List<object>();
            for (int i = 0; i < numberOfRows; i++) { objList.Add(new object()); }

            Content = new ListView()
            {
                RowHeight = 155,
                ItemsSource = objList,
                ItemTemplate = new DataTemplate(typeof(RadioCell))
            };
        }
    }

    public class RadioCell : ViewCell
    {
        public RadioCell()
        {
            //New Group Name
            string group = Guid.NewGuid().ToString();
            View = new StackLayout
            {
                Spacing = 0,
                Padding = 5,
                Children = {
                    new Label { Text = "Options?"},
                    new RadioButton { Text = "OPTION 1", GroupName = group },
                    new RadioButton { Text = "OPTION 2", GroupName = group },
                    new RadioButton { Text = "OPTION 3", GroupName = group }
                }
            };
        }
    }

How to get current page in Shell?

$
0
0

Hi.
I need to get a current presented page in Shell. I see a property PresentedPage in runtime. But can't see this property in code.

How can I get this?
Note: I don't need a route, I need real page object

WebNavigatingEventArgs e.Cancel=true not working on Android

$
0
0

I'm trying to make a WebView open all external links in a browser rather than within the WebView itself and have hit a few snags. I have a custom WebViewRenderer that resizes the webview to the size of the content and consequently my Navigating events where not firing. The Accepted Answer here solved that issue and Adam's answer here got the links opening in a browser. However when I move back to my app the page has also been navigated to in the WebView so it appears that the e.Cancel=true did not halt the WebView's usual navigation functionality.

I've seen mention here of a similar issue that was apparently solved in 4.0 but I'm on 4.7. I can work around this issue by overriding ShouldOverrideUrlLoading in my custom WebViewClient for my renderer but that method had been marked as obselete so I'm guessing there is a better way to handle this.

Below is my current renderer.

public class DynamicSizeWebViewRenderer : WebViewRenderer
    {
        public static int _webViewHeight;
        static Xamarin.Forms.WebView _xwebView = null;
        WebView _webView;

        public DynamicSizeWebViewRenderer(Android.Content.Context context) : base(context)
        {
        }

        class DynamicSizeWebViewClient : WebViewClient
        {
            WebView _webView;

            DynamicSizeWebViewRenderer _renderer;

            public DynamicSizeWebViewClient(DynamicSizeWebViewRenderer renderer)
            {
                _renderer = renderer ?? throw new ArgumentNullException("renderer");
            }

            public async override void OnPageFinished(WebView view, string url)
            {
                try
                {
                    _webView = view;
                    if (_xwebView != null)
                    {
                        view.Settings.JavaScriptEnabled = true;
                        await Task.Delay(100);
                        string result = await _xwebView.EvaluateJavaScriptAsync("(function(){return document.body.scrollHeight;})()");
                        _xwebView.HeightRequest = Convert.ToDouble(result);
                    }
                    base.OnPageFinished(view, url);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message}");
                }
            }

            public override bool ShouldOverrideUrlLoading(WebView view, string url)
            {
                var args = new WebNavigatingEventArgs(WebNavigationEvent.NewPage, new UrlWebViewSource { Url = url }, url);
                _renderer.ElementController.SendNavigating(args);
                return true;
            }

            //public override void OnPageStarted(AWebView view, string url, Bitmap favicon)
            //{
            //  base.OnPageStarted(view, url, favicon);

            //  var args = new WebNavigatingEventArgs(WebNavigationEvent.NewPage, new UrlWebViewSource { Url = url }, url);
            //  _renderer.ElementController.SendNavigating(args);
            //}
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);
            _xwebView = e.NewElement as Xamarin.Forms.WebView;
            _webView = Control;

            if (e.OldElement == null)
            {
                _webView.SetWebViewClient(new DynamicSizeWebViewClient(this));
            }

        }
    }

Shape Disappear After Update Version Xamarin Forms

$
0
0

Hi anyone knows why my shape not appear after update version xamarin forms to 4.8.0.1269?

This code shows love shape -->

Is there any method to create this shape besides image.


when stacklayout will has a border?

$
0
0

there will be a border in stacklayout in conditions

when it will has a border and how to remove it?

How to open an Expander with DoubleTap

$
0
0

Sometimes I wonder why such obvious things are not implemented. I would like to open an expander with a DoubleTap. I would like to use the normal tap gesture for other things, e.g. for marking an item in a ListView. If someone wants to have details about the item, he should click twice to open the expander. I have experimented with "IsEnabled", but then the whole content is shown as disabled and I don't want that. Am I missing a build in feature ?

How to use Switch with TapGestureRecognizer in listview?

$
0
0
<ListView ItemsSource="{Binding UserList}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout>
                    <Switch OnColor="#D27474" ThumbColor="#D27474" IsToggled="{Binding IsActive}">
                        <Switch.Behaviors>
                            <behaviors:EventToCommandBehavior EventName="Toggled" Command="{Binding TestCommand}"/>
                        </Switch.Behaviors>
                    </Switch>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Whenever my Listview is initialize and my IsActive property value is initialize Toggle event is automatically called and it will goes to circular.Is there any way to prevent this?

SwipeItem oversized in Xamarin Forms

$
0
0

Hi,

can't figure out how to get right SwipeItem height.
I am getting this:

Here is peace of my xaml:

   <Frame BorderColor="Black" Padding="10,10,10,10">
        <RefreshView IsRefreshing="{Binding IsBusy, Mode=TwoWay}" Command="{Binding LoadItemsCommand}">
            <CollectionView ItemsSource="{Binding OperationItems}" x:Name="ItemsCollectionView" >
                <d:CollectionView.ItemsSource>
                    <x:Array Type="{x:Type x:String}">
                        <x:String>Barcode</x:String>
                        <x:String>Barcode</x:String>
                        <x:String>Barcode</x:String>
                        <x:String>Barcode</x:String>
                        <x:String>Barcode</x:String>
                        <x:String>Barcode</x:String>
                    </x:Array>
                </d:CollectionView.ItemsSource>
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <SwipeView Grid.Row="0">
                            <SwipeView.RightItems>
                                <SwipeItems Mode="Reveal" SwipeBehaviorOnInvoked="Close">
                                    <SwipeItem Text="{x:Static resources:AppResources.menu_delete}"
                                               BackgroundColor="#AD1457" 
                                               Command="{Binding    Source={x:Reference ItemsCollectionView},
                                                                    Path=BindingContext.DeleteItemCommand}" 
                                               CommandParameter="{Binding row}"/>
                                </SwipeItems>
                            </SwipeView.RightItems>
                            <Grid Padding="0,0,0,10">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="2*" />
                                    <ColumnDefinition Width="3*" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto"/>
                                    <RowDefinition Height="auto"/>
                                </Grid.RowDefinitions>
                                <Label Grid.Column="0" Grid.Row="0" Text="{Binding barcode}" 
                                        d:Text="{Binding .}"
                                        LineBreakMode="NoWrap" 
                                        Style="{DynamicResource ListItemTextStyle}" 
                                        FontSize="12" HorizontalOptions="StartAndExpand" TextColor="Black"/>
                                <Label x:Name="LabelHeight" Grid.Column="1" Grid.Row="0" Text="{Binding name}" 
                                        d:Text="Name"
                                        LineBreakMode="NoWrap"
                                        Style="{DynamicResource ListItemDetailTextStyle}"
                                        FontSize="10" HorizontalOptions="StartAndExpand" TextColor="Black" MaxLines="2"/>
                                <Label Grid.Column="2" Grid.Row="0" Text="{Binding quantity}" 
                                        d:Text="Qty"
                                        LineBreakMode="NoWrap"
                                        Style="{DynamicResource ListItemDetailTextStyle}"
                                        FontSize="12" HorizontalOptions="End" TextColor="Black"/>
                                <BoxView Grid.Row="1" BackgroundColor="Black" HeightRequest="1" Grid.ColumnSpan="3"/>
                            </Grid>
                        </SwipeView>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </RefreshView>
    </Frame>

How to stop the activity indicator after click on button /navigate to the next page

$
0
0

Hello,
I have the login form on which i have added the activity indicator ,I want to work the my application like when I enter the credentials activity indicator should start & when i click on login button it should stop.

But now in my application activity indicator is continously running.

In XAML file below code is there

In .CS file below code is there

please give me suggestion to how to solve.

How to add custom fonts on xamarin forms

$
0
0

Hello,

I work on a project xamarin forms, and i want to add a new font family.
i followed the official tutorial and it's not working!
i downloaded a font fantasy.ttf and then i paste it in asset of android project then i added this code in app.xaml


this don't work.
(#Final Fantasy i finded it in properties of the Fantasy.tff file in title)

How can i solve this?
thanks!

Xamarin Forms - Cascading ListView/CollectionView cell animation

$
0
0

In our project, we got a requirement to implement something like a cascading ListView cell animation (cell loads up one-by-one, instead of just in one shot). What are my options to implement it easily in Xamarin Forms? Would I have to go in the direction of writing Custom Renderer to implement it? The example is given in the below animation.

Any suggestions are much appreciated.

Thank you in advance.


searchbar CursorDrawable (Cursor color ).

$
0
0

How to change searchbar CursorDrawable (Cursor color ) in xamarin forms?

Color palatte in xamarin

$
0
0

Hello everyone!
as am new to this platform I don't know how to achieve this in xamarin
I want a color palette in xamarin where I can select any one color and write code on the selection of colors

How to define a plattform specific, light and dark mode dependent color (for a BarBackgroundColor)

$
0
0

I like my Navigation Bars to have different BarBackgroundColor & BarTextColor. It worked fine so far like follows. But now I have problems to alter Colors with regard to OS light mode and dark mode. I thought a solution using "AppThemeBinding" would be logical. I use this concept for all view types. But here it throws an - System.Reflection.TargetInvocationException - I cannot solve. The problem seems to be "Specific cast ist not valid"

Please assist. I searched for solutions in different places. Maybe my thinking/concept is wrong?

//Solution without OS light/dark mode adaption--

//App.xaml.cs

var page = new x_temp.TestStartPage(); //content page
MainPage = new NavigationPage(page)
            {
                Style = (Style)Application.Current.Resources["NavBarStyle"]
            };

//App.xaml

 <Style TargetType="NavigationPage" x:Key="NavBarStyle">  
                <Setter Property="BarBackgroundColor">
                    <Setter.Value>
                        <OnPlatform x:TypeArguments="Color" >
                            <On Platform="Android" Value="#DBE5FA"/>
                            <On Platform="iOS" Value="#FFFFFF"/>
                        </OnPlatform>
                    </Setter.Value>
                </Setter>
        </Style>

//Attempt with OS light/dark mode adaption

        <Style TargetType="NavigationPage" x:Key="NavBarStyle">  
            <Setter Property="BarBackgroundColor">
                <Setter.Value>
                    <OnPlatform x:TypeArguments="Color" >
                         <On Platform="Android" Value="_{AppThemeBinding
                            Light=#DBE5FA,
                            Dark=#584F4F,
                            Default=#DBE5FA}"_/>
                        <On Platform="iOS" Value="_{AppThemeBinding
                            Light=#FFFFFF,
                            Dark=#584F4F,
                            Default=#FFFFFF}"_/>
                    </OnPlatform>
                </Setter.Value>
            </Setter>
        </Style>

how to make Qr code reader in pocket pda with android?

$
0
0

Hello
I'm doing a code reader which already works with the camera but I want it to work with a pocket PDA that has SCAN integrated
Any idea how I could do it? Will it only be with some permission or is the code different?
I just start with the apps and I do not fully understand their logic

Best Mobile app development

$
0
0

Mobile app development is the process of creating software applications that run on a mobile devices, and a typical mobile applications utilizes a network connection work with remote computing resource. Mobile app development Phoenix our company provide a powerful multi function mobile solution is require for the enterprise which is well strategized for more visit Mobile app development Phoenix around various operational requirements across the organization. mobile application is the set of processes and procedures involved in writing software for small , Mobile app development Phoenix wireless computing devices. Like web applications development . Mobile app development Phoenix has its roots in more traditional software development. one critical difference , however is that mobile apps are often specifically to take advantages of the unique features a particular Mobile app development Phoenix devices offers. Our company provide the end user with a better user experience than a traditional website that uses responsive design . Progressive wen apps may also be referred to ad instant mobile apps

Viewing all 79144 articles
Browse latest View live


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