Xamarin Forms MvxListView is populating with data, but the Binding at the MvxTextCell Is not showing Text

52 views Asked by At

Prefacing this by saying I am by no means a Xamarin dev, and am just trying to add to an existing project.

I have a List View that is adding getting data added to it via an entry and button, and it is definitely updating the List View, because it is adding a new row every time, and it is properly being added to the ObservableCollection, but for some reason the text is just not showing up.

XAML

<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:model="clr-namespace:App.Entites"
                 xmlns:mvx="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
                 xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
                 xmlns:vm="clr-namespace:App.ViewModels"
                 x:DataType="vm:MyViewModel"
                 x:Class="App.Views.MyView">
    <Grid Padding="20"
          BackgroundColor="{AppThemeBinding Light=White, Dark=DarkGray}"
          HorizontalOptions="Center"
          VerticalOptions="Center"
          WidthRequest="250"
          HeightRequest="400">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label Grid.Row="0" Text="List Title" HorizontalTextAlignment="Center" FontSize="Large" />

        <mvx:MvxListView x:Name="ListName" Grid.Row="1" ItemsSource="{Binding MyList}">
            <mvx:MvxListView.ItemTemplate>
                <DataTemplate>
                    <mvx:MvxTextCell Text="{Binding .}" TextColor="Black"/>
                </DataTemplate>
            </mvx:MvxListView.ItemTemplate>
        </mvx:MvxListView>
        
        <StackLayout Grid.Row="2" Orientation="Vertical" HorizontalOptions="Center" Spacing="10">
            <Entry Placeholder="New Item" WidthRequest="250" Text="{Binding NewItem}" x:Name="NewDest" HorizontalTextAlignment="Center" ClearButtonVisibility="WhileEditing"/>
            <Button Text="Add Item" Command="{Binding AddCommand}" Style="{StaticResource BlueButton}"/>
        </StackLayout>
    </Grid>
</pages:PopupPage>

View Model

private ObservableCollection<string> _myList = new ObservableCollection<string>();
public ObservableCollection<string> MyList
{
    get
    {
        return _myList;
    }
    set
    {
        if (_myList != value)
        {
            _myList = value;
            RaisePropertyChanged(nameof(_myList));
        }
    }
}

private string _newItem;
public string NewItem
{
    get { return _newItem; }
    set { SetProperty(ref _newItem, value); }
}

private MvxCommand showListCommand;
public IMvxCommand ShowListCommand
{
    get
    {
        showListCommand ??= new MvxCommand(ShowList);
        return showListCommand;
    }
}

private void ShowList()
{
    PopupNavigation.Instance.PushAsync(new MyListView(this));
}
public IMvxCommand<string> AddCommand => new MvxCommand<string>(AddItem);

private void AddItem(string item)
{
    MyList.Add(_newItem);
    NewItem = string.Empty;
}

Here is what the output looks like (I changed some of the names of labels and what not in the code, but the issue is the same:

List Issue

I have tried using an object and accessing the 'Name' attribute. I am expecting the text to fill in the blanks. (Below is an example with constant Text instead of a Binding)

Example

Even in this example when I add a destination it will add a new row into the list, and when I check the ObservableCollection it is also getting updated.

0

There are 0 answers