Binding Update become blank on UWP RRS feed

  • Question

  • User179531 posted

    Hello all,

    I am a beginner and just starting to use Xamarin.Forms for cross platform.

    At first, the thing work fine in Android, but not working in Universal Windows Platform.

    I have create the Xamarin.Forms follow UWP instruction at https://developer.xamarin.com/guides/xamarin-forms/windows/getting-started/universal

    The problem: - When I change the data in binding object, the label become empty.

    FirstPage.xaml <StackLayout Orientation="Vertical"> <ListView x:Name="LvUser"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <Grid Padding="5"> <Label Text="{Binding UserName}" /> </Grid> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> <Button Text="change username" Clicked="changeUserNameClicked" /> </StackLayout>

    User.cs namespace XamarinPCL { public class User { public string username { get; set; } } }

    UserViewModel.cs namespace XamarinPCL { public class UserViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(String propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } private User _user; public String UserName { get { return _user.username; } set { _user.username = value; NotifyPropertyChanged("UserName"); } } public UserViewModel(User user) { _user = user; } } }

    FirstPage.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Xamarin.Forms; using System.Collections.ObjectModel; namespace XamarinPCL { public partial class FirstPage : ContentPage { ObservableCollection<UserViewModel> _userVM = new ObservableCollection<UserViewModel>(); UserViewModel _uvm1 = new UserViewModel(new User() { username = "user 1" }); UserViewModel _uvm2 = new UserViewModel(new User() { username = "user 2" }); public FirstPage() { InitializeComponent(); } protected override void OnAppearing() { base.OnAppearing(); _userVM.Add(_uvm1); _userVM.Add(_uvm2); LvUser.ItemsSource = _userVM; } private void changeUserNameClicked(object sender, EventArgs e) { _uvm1.UserName = "i changed"; } } }

    When I click on the item, the row #1 become empty, any idea?

    Monday, December 28, 2015 4:11 AM

All replies

  • User128591 posted

    It's a bug, currently must set grid's row or column's width and height

    Monday, December 28, 2015 10:01 AM
  • User179531 posted

    @Gruan said: It's a bug, currently must set grid's row or column's width and height

    Which grid do you mean? the grid inside the ViewCell?

    However, I have modified the ListView and also the Grid

    <ListView x:Name="LvUser" HeightRequest="150" WidthRequest="300"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <Grid Padding="5" HeightRequest="50" WidthRequest="300"> <Label Text="{Binding UserName}" /> </Grid> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>

    but still show blank, any solution?

    ps: I am using Xamarin.Forms

    Tuesday, December 29, 2015 1:53 AM
  • User128591 posted

    Grid's column or row's width and height.

    Issue : Image in ListView's ViewCell on UWP

    Hi, I'm trying add image into ListView's ViewCell. On Android / WP it's all work fine. But on UWP , something is very inconceivable,

    Environment: Xamarin.Forms UWP 10586

    First, Image direct in ViewCell.View, it will show: ~~~ ~~~

    If wrapp it with Grid, it not show: ~~~ ~~~

    If wrap it with StackLayout and Grid, it will show again: ~~~ ~~~

    If define a row with exactly Height, image not show, whatever with or without Stacklayout : ~~~ ~~~

    if set row height as auto or not define height, image will show again!

    Tuesday, December 29, 2015 3:16 AM
  • User179531 posted

    Thank you Gruan, you are really helpful.

    After reading your case, I manage to make my sample work, solution as below.

    <ListView x:Name="LvUser"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <Grid Padding="5"> <Grid.RowDefinitions> <RowDefinition Height="auto"/> </Grid.RowDefinitions> <Label Text="{Binding UserName}" Grid.Row="0" /> </Grid> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>

    But it is very inconvenience to require this kind of workaround to complete a small job, and sometime we cannot know which combination will destroy it again.

    I had struggled in this problem for almost 2 days to make it work (which done easily in actual UWP), I feel maybe Xamarin.Forms is still not mature to build for UWP. I am worrying whether it will have more bug like this for me to challenge later on, so in your opinion, do you think I should go for actual UWP or use Xamarin.Forms and shared for ios/android/uwp.

    Tuesday, December 29, 2015 3:44 AM
  • User176749 posted

    Still today isn't Mature. I also spent a lot of time to fix uwp and my case is more complicated

    Thursday, January 19, 2017 1:28 AM