Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Binding to INotifyCollectionChanged event

Closed Thread
 
Thread Tools Display Modes
Old 06-09-2008   #1 (permalink)
Some Bloke's Avatar
Some Bloke
Guest


 



Binding to INotifyCollectionChanged event

I am trying to bind a dependency property to an aggregate of a
collection. I've implemented a wrapper around a Dictionary that
implements INotifyCollectionChanged to fire the event when items are
added or removed.

Debugging through it I notice that there is nothing attached to the
event after I bind to it which I expected the SetBinding to do as I
don't know what delegate to bind to the event.

I've tried a test with just an ObservableCollection to see if I was
missing something but that doesn't work either.

How do I wire up the event to the binding to get my test to pass?

Here's my test code:

[TestClass()]
public class ObservableDictionaryTest : DependencyObject
{
public class MaxDoubleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
if (value is IEnumerable<double>)
{
return ((IEnumerable<double>)value).Max(); // using
Linq
}

throw new ArgumentException("Cannot covert " +
value.GetType() + " to IEnumerable<double>", "value");
}

public object ConvertBack(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

public double Max
{
get { return (double)GetValue(MaxProperty); }
}

public static readonly DependencyProperty MaxProperty =
DependencyProperty.Register("Max", typeof(double),
typeof(ObservableDictionaryTest), new PropertyMetadata(0.0));

[TestMethod()]
public void TestBindingToObservableCollection()
{
ObservableCollection<double> values = new
ObservableCollection<double>();
values.Add(1.0);
values.Add(2.0);
values.Add(3.0);

Binding b = new Binding();
b.Converter = new MaxDoubleConverter();
b.Source = values;
b.Mode = BindingMode.OneWay;
BindingOperations.SetBinding(this, MaxProperty, b);

Assert.AreEqual(3.0, Max); // this works

values.Add(4.0);
Assert.AreEqual(4.0, Max); // this doesn't

values.Remove(4.0);
Assert.AreEqual(3.0, Max);
}
}





Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Animating bounding INotifyCollectionChanged events in WPF fil Avalon 0 02-20-2008 08:40 PM
Binding inside binding question Yoavo Avalon 0 12-03-2007 08:24 AM
Binding to a Foreign Key Binding? -=B3N=- Avalon 0 06-14-2007 06:45 AM
Binding Question (Binding in General) Jason Avalon 2 05-09-2007 04:41 AM
Windows Event Log fails to translate event description. Deepak Jha Vista General 0 12-15-2006 06:30 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50