Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a Day.cs class who have this propriety :

C#
public ObservableCollection ListeTache
        {
            get { return this._listeTache; }
            set
            {
                _listeTache = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("ListeTache"));
                }
            }
        }

        public string Notes
        {
            get { return this._notes; }
            set
            {
                _notes = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Notes"));
                }
            }
        }

public bool Enabled
        {
            get { return _enabled; }
            set
            {
                _enabled = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Enabled"));
                }
            } }





My Day.cs class have :

C#
public Day(){
            _listeTache = new ObservableCollection();
            _listeTache.CollectionChanged += ListeTache_Changed;
        }

        private void ListeTache_Changed(object sender, NotifyCollectionChangedEventArgs e)
        {
            MessageBox.Show("ok"); 
}


I bind Notes like that :

XML
<TextBox IsEnabled="{Binding IsEnabled}" Text="{Binding Notes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" TextWrapping="Wrap" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Auto" removed="{x:Null}" Foreground="White" />


I bind ListeTache like that :

XML
<ListBox x:Name="ListeTaches" IsEnabled="{Binding IsEnabled}" ItemsSource="{Binding ListeTache}" IsSynchronizedWithCurrentItem="True" FontSize="10" PreviewMouseDown="PreviewMouseDownClick_clear" MouseDoubleClick="doubleClic">
<Style.Triggers>



In my class Calendar.cs I have this event :

C#
private void Day_Changed(object sender, PropertyChangedEventArgs e)
        {
            if (DayChanged == null)
            {
                return;
            }

            DayChanged(this, new DayChangedEventArgs(sender as Day));
        }


I use my Generic.xaml in other projet like that :

XML
<Scan:Calendar x:Name="Calendar" DayChanged="Calendar_DayChanged" Margin="0,82,0,0" HorizontalContentAlignment="Center"/>


When I start this app for the first time I receive my message "ok" for each items already in ListeTache.

After starting, When I change the propriety "Notes", the event is fire and it's okay but when I add or Remove an element in my ListeTache I never get an event.

How can I do ? Thanks in advance for your reply guys.
Posted
Updated 31-Mar-14 0:31am
v2
Comments
johannesnestler 31-Mar-14 7:17am    
Looks ok, are you shure you don't reset (set a new reference)your ListeTache property? Anyway this smells like bad design (why should anyone from outside your day class should set a new observable list? (use lazy initialization of an internal instance would be prefered by me...). Anyway you can also exclude this as cause of your error, by attaching/removing the eventhandler (to listen to collection changes) inside your ListeTache property (and also check if it's already the same instance before doing so!
trainor_x 31-Mar-14 8:39am    
Thank you. I try some of your idea but nothing happened.
I think I'm doing something wrong in my ResourceDictionnary.
I have a event in ResourceDictionnary code behind which add a "Tache" in my database but I never update my listbox after adding "Tache" in database because I can't access my listbox in ressourcedictionnary code behind ?

Do you understand what I say ? ^^
johannesnestler 31-Mar-14 9:28am    
Hmm, maybe I don't understand yes... But I don't see what your database updating should have todo with seemingly "not working" binding. ->You say if you update your listbox items no change notification is generated... (I hope you ruled that reason out which I guessed before ). I don't think your ResourceDictionary handling is the problem. Sounds more like some conceptual mistake. What I was wondering what this piece of code should do (doesn't seem related to your problem, but who knows ...)
private void Day_Changed(object sender, PropertyChangedEventArgs e)
{
if (DayChanged == null)
{
return;
}

DayChanged(this, new DayChangedEventArgs(sender as Day));
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900