Click here to Skip to main content
15,880,405 members
Home / Discussions / Mobile
   

Mobile

 
QuestionUSB Cable Between PC And Android Pin
C-P-User-38-Mar-19 5:30
C-P-User-38-Mar-19 5:30 
SuggestionRe: USB Cable Between PC And Android Pin
David Crow8-Mar-19 9:40
David Crow8-Mar-19 9:40 
GeneralRe: USB Cable Between PC And Android Pin
C-P-User-310-Mar-19 4:20
C-P-User-310-Mar-19 4:20 
AnswerRe: USB Cable Between PC And Android Pin
Richard Deeming8-Mar-19 9:43
mveRichard Deeming8-Mar-19 9:43 
QuestionXamarin forms and SQLIte database Pin
Mycroft Holmes25-Feb-19 19:37
professionalMycroft Holmes25-Feb-19 19:37 
SuggestionRe: Xamarin forms and SQLIte database Pin
David Crow26-Feb-19 4:15
David Crow26-Feb-19 4:15 
GeneralRe: Xamarin forms and SQLIte database Pin
Mycroft Holmes26-Feb-19 12:24
professionalMycroft Holmes26-Feb-19 12:24 
QuestionCross Platform Xamarin MVVM ListView binding to ViewModel List not working Pin
Stephen Holdorf19-Feb-19 2:46
Stephen Holdorf19-Feb-19 2:46 
I am trying to implement a MVVM ContentPage with a ListView that needs to bind to populated generic list of XML model objects in a ViewModel but the binding fails. The code that is shown calls an API that does return a valid list of XML data. The same code works fine when the binding is done directly in the code behind of the XAML Xamarin contentpage by setting the ItemSource in the codebehind. As said, the problem only happens when trying to pass the ListView through the ViewModel assigned to the contentpage. I have stepped through the code in the ViewModel and the ListView is populated successfully but the binding just doesn't work. I have other controls that are on the page not shown that the model binding does work for but the only control that doesn't work is the ListView. The code is shown below:

ViewModel:

namespace RestDemo.ViewModel
{
    
    public class ViewModel : INotifyPropertyChanged
    {
        public ViewModel ()
        {
           GetRequest();
        }

        List<XmlPizzaDetails> _objPizzaList;

        public List<XmlPizzaDetails> ObjPizzaList
        {
            get { return _objPizzaList; }

            set
            {
                if (_objPizzaList != value)
                {
                    _objPizzaList = value;
                    OnPropertyChanged("ObjPizzaList");
                }
            }
        }


        public async void GetRequest()
        {
            if (NetworkCheck.IsInternet())
            {

                Uri geturi = new Uri("http://api.androidhive.info/pizza/?format=xml"); //replace your xml url
                HttpClient client = new HttpClient();
                HttpResponseMessage responseGet = await client.GetAsync(geturi);
                string response = await responseGet.Content.ReadAsStringAsync();

                //Xml Parsing
                ObjPizzaList = new List<XmlPizzaDetails>();
                XDocument doc = XDocument.Parse(response);
                foreach (var item in doc.Descendants("item"))
                {
                    XmlPizzaDetails ObjPizzaItem = new XmlPizzaDetails();
                    ObjPizzaItem.ID = item.Element("id").Value.ToString();
                    ObjPizzaItem.Name = item.Element("name").Value.ToString();
                    ObjPizzaItem.Cost = item.Element("cost").Value.ToString();
                    ObjPizzaItem.Description = item.Element("description").Value.ToString();
                    ObjPizzaList.Add(ObjPizzaItem);
                }
                Progress = false;
            }
        }

    }
} 

XAML

Model Binding portion:

ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xlocal="clr-namespace:RestDemo.ViewModel"
             xmlns:local="clr-namespace:RestDemo"
             xmlns:Views="clr-namespace:RestDemo.Views"
             x:Class="RestDemo.XmlParsingPageBehavior">
    <ContentPage.BindingContext>
        <xlocal:ViewModel />
    </ContentPage.BindingContext>


Grid Binding Portion

<Frame Margin="5, 5, 5, 5" Grid.Row="2" Grid.Column="1" BackgroundColor = "Cyan">
    <ListView x:Name="PizzaListView" ItemsSource="{Binding ObjPizzaList}"  Margin="5, 0, 5, 0" Grid.Row="2" Grid.Column="1" HorizontalOptions="FillAndExpand" HasUnevenRows="True">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid HorizontalOptions="FillAndExpand" Margin="0,0,0,0" Padding="20">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Label Text="{Binding Name}" HorizontalOptions="StartAndExpand" Grid.Row="0" TextColor="Blue"  FontAttributes="Bold"/>
                        <Label Text="{Binding Cost}" HorizontalOptions="StartAndExpand" Grid.Row="1" TextColor="Orange"  FontAttributes="Bold"/>
                        <Label Text="{Binding Description}" HorizontalOptions="StartAndExpand" Grid.Row="2" TextColor="Gray"  FontAttributes="Bold"/>
                        <BoxView HeightRequest="2" Margin="0,10,10,0" BackgroundColor="Gray" Grid.Row="3" HorizontalOptions="Fill" />
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</Frame>

AnswerRe: Cross Platform Xamarin MVVM ListView binding to ViewModel List not working Pin
Mycroft Holmes19-Feb-19 11:11
professionalMycroft Holmes19-Feb-19 11:11 
GeneralRe: Cross Platform Xamarin MVVM ListView binding to ViewModel List not working Pin
Stephen Holdorf20-Feb-19 4:48
Stephen Holdorf20-Feb-19 4:48 
QuestionXamarin Forms Picker binding Pin
Mycroft Holmes21-Dec-18 19:35
professionalMycroft Holmes21-Dec-18 19:35 
Questionmobile program Pin
Member 1408773812-Dec-18 20:07
Member 1408773812-Dec-18 20:07 
Questionreturn all html codes of page instead of one string (by B4A commands) Pin
Member 1352250115-Nov-18 20:38
Member 1352250115-Nov-18 20:38 
QuestionAdvice required Pin
Mycroft Holmes9-Nov-18 17:22
professionalMycroft Holmes9-Nov-18 17:22 
AnswerRe: Advice required Pin
Adrian Mikeliunas20-Nov-18 10:49
Adrian Mikeliunas20-Nov-18 10:49 
GeneralRe: Advice required Pin
Mycroft Holmes20-Nov-18 11:22
professionalMycroft Holmes20-Nov-18 11:22 
QuestionTapGestureRecognizer on an Image on Tab not work Pin
Vimalsoft(Pty) Ltd8-Nov-18 11:34
professionalVimalsoft(Pty) Ltd8-Nov-18 11:34 
Questionprayer time Pin
Sayed Gulab Hussain Shah3-Nov-18 22:30
Sayed Gulab Hussain Shah3-Nov-18 22:30 
AnswerRe: prayer time Pin
OriginalGriff3-Nov-18 22:32
mveOriginalGriff3-Nov-18 22:32 
AnswerRe: prayer time Pin
Afzaal Ahmad Zeeshan4-Nov-18 9:32
professionalAfzaal Ahmad Zeeshan4-Nov-18 9:32 
QuestionQuestion about copyright laws Pin
ericbruhaha23-Oct-18 15:21
ericbruhaha23-Oct-18 15:21 
AnswerRe: Question about copyright laws Pin
Richard MacCutchan23-Oct-18 22:36
mveRichard MacCutchan23-Oct-18 22:36 
AnswerRe: Question about copyright laws Pin
abayomicharm24-Oct-18 19:44
abayomicharm24-Oct-18 19:44 
AnswerRe: Question about copyright laws Pin
Eddy Vluggen25-Oct-18 1:10
professionalEddy Vluggen25-Oct-18 1:10 
GeneralRe: Question about copyright laws Pin
ericbruhaha25-Oct-18 6:42
ericbruhaha25-Oct-18 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.