locked
Databinding UI not updating RRS feed

  • Question

  • Hi

     

    I’m having some trouble figuring out this databinding. I’ve added my binding object in the app.xaml.cs file and assign it to the DataContext in my MainPage


       public MainPage()

            {

                this.InitializeComponent();

     

                this.DataContext = ((App) (App.Current)).SmsMessage;


    My SmSMessage has a property List<Receivers> Receivers and in my Appbar I have a gridview that binds to the receivers

    <GridView Name="ReceiversGridView" ShowsScrollingPlaceholders="False" Height="65" Width="auto" ItemsSource="{Binding Path=Receivers, Mode=TwoWay}"

    SelectionMode="Single" IsSwipeEnabled="False" DragItemsStarting="ReceiversGridView_OnDragItemsStarting" CanDragItems="True" >

    The SmsMessage class implements INotifyPropertyChanged.

      public class SmsMessage : INotifyPropertyChanged

        {

            private string _message;

            private string _senderInitial;

            private int _messageLenght;

            private string _receiversCount;

            private DateTime _sendLaterDate = DateTime.Now;

            private TimeSpan _sendTime = DateTime.Now.TimeOfDay;

            private bool _sendLater;

            private bool _toLong;

            private int _totalMessages;

            private List<Receiver> _receivers;

      public List<Receiver> Receivers

            {

                get

                {

                    if (_receivers == null)

                    {

                        _receivers = new List<Receiver>();

                    }

                    return _receivers;

                }

                set

                {

                    _receivers = value;

                    OnPropertyChanged("Receivers");

                }

            }


     
    My Receiver Class also implements INotifyPropertyChanged

      public class Receiver : INotifyPropertyChanged

        {

            private string _displayName;

            private string _initialer;

            private string _mobil;

            private string _afdeling;

            private byte[] _photo;

            private ImageSource _imageSource;



    When I drag an ithem out of the gridview and drops it I remove the item from the Receivers list (this part works fine) but my Ui dosen't update

    see image for dragging




    Why is the UI not updating?

    /Jacob


    Wednesday, October 1, 2014 8:15 AM

Answers

  • I think you need an ObservableCollection rather than List.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Saugmann Wednesday, October 1, 2014 1:48 PM
    Wednesday, October 1, 2014 1:31 PM
    Moderator

All replies

  • I think you need an ObservableCollection rather than List.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Saugmann Wednesday, October 1, 2014 1:48 PM
    Wednesday, October 1, 2014 1:31 PM
    Moderator
  • Thanks :-D
    Wednesday, October 1, 2014 1:48 PM