├── .gitignore
├── CodeBinding.Rx.Test
├── CodeBinding.Rx.Test.csproj
├── ObservableExTest.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── CodeBinding.Rx
├── CodeBinding.Rx (net35).csproj
├── CodeBinding.Rx.csproj
├── CodeBinding.Rx.nuspec
├── ObservableBindingTarget.cs
├── ObservableEx.cs
├── ObservableMultiValueConverter.cs
├── ObservableValueConverter.cs
├── ObservableValueConverterBase.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── CodeBinding.Test
├── BindingExTest.cs
├── CodeBinding.Test.csproj
├── GenericBindingTarget.cs
├── GenericNotifyPropertyChanged.cs
└── Properties
│ └── AssemblyInfo.cs
├── CodeBinding.sln
├── CodeBinding.vsmdi
├── CodeBinding
├── BindingEx.cs
├── BindingTarget.cs
├── ClearBindingDisposable.cs
├── CodeBinding (net35).csproj
├── CodeBinding.csproj
├── CodeBinding.nuspec
├── ExpressionValueConverter.cs
└── Properties
│ └── AssemblyInfo.cs
├── Documentation
└── Observable Extension API Specification.docx
├── LICENSE
├── Local.testsettings
├── Nuget
├── CodeBinding.Rx.nuspec
└── CodeBinding.nuspec
├── README.md
├── Samples
├── MultiBinding
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── MultiBinding.csproj
│ └── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
├── SingleBinding
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── SingleBinding.csproj
└── UserRegistration.Rx
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── MainWindowViewModel.cs
│ ├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
│ ├── UserRegistration.Rx.csproj
│ ├── app.config
│ └── packages.config
├── TraceAndTestImpact.testsettings
└── packages
├── Rx-Core.1.0.2856.0
├── Rx-Core.1.0.2856.0.nupkg
└── lib
│ ├── Net35
│ ├── System.CoreEx.chm
│ ├── System.CoreEx.dll
│ ├── System.CoreEx.xml
│ ├── System.Observable.chm
│ ├── System.Observable.dll
│ ├── System.Observable.xml
│ ├── System.Threading.chm
│ ├── System.Threading.dll
│ ├── System.Threading.xml
│ └── redist.txt
│ ├── Net4
│ ├── System.CoreEx.chm
│ ├── System.CoreEx.dll
│ ├── System.CoreEx.xml
│ └── redist.txt
│ └── SL4
│ ├── System.CoreEx.chm
│ ├── System.CoreEx.dll
│ ├── System.CoreEx.xml
│ ├── System.Observable.chm
│ ├── System.Observable.dll
│ ├── System.Observable.xml
│ └── redist.txt
├── Rx-Main.1.0.10605
├── Rx-Main.1.0.10605.nupkg
└── lib
│ ├── Net35
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
│ ├── Net4
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
│ ├── SL3-WP
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
│ └── SL4
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
├── Rx-Main.1.0.2856.0
├── Rx-Main.1.0.2856.0.nupkg
└── lib
│ ├── Net35
│ ├── System.Reactive.chm
│ ├── System.Reactive.dll
│ └── System.Reactive.xml
│ ├── Net4
│ ├── System.Reactive.chm
│ ├── System.Reactive.dll
│ └── System.Reactive.xml
│ └── SL4
│ ├── System.Reactive.chm
│ ├── System.Reactive.dll
│ └── System.Reactive.xml
├── Rx-Main.1.1.10425
├── Rx-Main.1.1.10425.nupkg
└── lib
│ ├── Net35
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
│ ├── Net4
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
│ ├── SL3-WP
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
│ ├── SL3
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
│ ├── SL4
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
│ └── SL5
│ ├── System.Reactive.XML
│ └── System.Reactive.dll
├── Rx-Xaml.1.1.10425
├── Rx-Xaml.1.1.10425.nupkg
└── lib
│ ├── Net35
│ ├── System.Reactive.Windows.Threading.XML
│ └── System.Reactive.Windows.Threading.dll
│ ├── Net4
│ ├── System.Reactive.Windows.Threading.XML
│ └── System.Reactive.Windows.Threading.dll
│ ├── SL3-WP
│ ├── System.Reactive.Windows.Threading.XML
│ └── System.Reactive.Windows.Threading.dll
│ ├── SL3
│ ├── System.Reactive.Windows.Threading.XML
│ └── System.Reactive.Windows.Threading.dll
│ ├── SL4
│ ├── System.Reactive.Windows.Threading.XML
│ └── System.Reactive.Windows.Threading.dll
│ └── SL5
│ ├── System.Reactive.Windows.Threading.XML
│ └── System.Reactive.Windows.Threading.dll
├── reactiveui-core.2.3.1.0
├── lib
│ ├── Net35
│ │ ├── ReactiveUI_35.dll
│ │ ├── ReactiveUI_35.pdb
│ │ └── ReactiveUI_35.xml
│ ├── Net4
│ │ ├── ReactiveUI.dll
│ │ ├── ReactiveUI.pdb
│ │ └── ReactiveUI.xml
│ ├── SL3-WP
│ │ ├── ReactiveUI_WP7.dll
│ │ ├── ReactiveUI_WP7.pdb
│ │ └── ReactiveUI_WP7.xml
│ └── SL4
│ │ ├── ReactiveUI_SL4.dll
│ │ ├── ReactiveUI_SL4.pdb
│ │ └── ReactiveUI_SL4.xml
└── reactiveui-core.2.3.1.0.nupkg
├── reactiveui-xaml.2.3.1.0
├── lib
│ ├── Net35
│ │ ├── ReactiveUI.Xaml_35.dll
│ │ ├── ReactiveUI.Xaml_35.pdb
│ │ └── ReactiveUI.Xaml_35.xml
│ ├── Net4
│ │ ├── ReactiveUI.Blend.dll
│ │ ├── ReactiveUI.Blend.pdb
│ │ ├── ReactiveUI.Blend.xml
│ │ ├── ReactiveUI.Xaml.dll
│ │ ├── ReactiveUI.Xaml.pdb
│ │ └── ReactiveUI.Xaml.xml
│ ├── SL3-WP
│ │ ├── ReactiveUI.Blend_WP7.dll
│ │ ├── ReactiveUI.Blend_WP7.pdb
│ │ ├── ReactiveUI.Blend_WP7.xml
│ │ ├── ReactiveUI.Xaml_WP7.dll
│ │ ├── ReactiveUI.Xaml_WP7.pdb
│ │ └── ReactiveUI.Xaml_WP7.xml
│ └── SL4
│ │ ├── ReactiveUI.Blend_SL4.dll
│ │ ├── ReactiveUI.Blend_SL4.pdb
│ │ ├── ReactiveUI.Blend_SL4.xml
│ │ ├── ReactiveUI.Xaml_SL4.dll
│ │ ├── ReactiveUI.Xaml_SL4.pdb
│ │ └── ReactiveUI.Xaml_SL4.xml
└── reactiveui-xaml.2.3.1.0.nupkg
└── repositories.config
/.gitignore:
--------------------------------------------------------------------------------
1 | *.suo
2 | *.user
3 | *.vspscc
4 | *.vssscc
5 | *.vs10x
6 | *.pidb
7 | *.userprefs
8 | bin/
9 | Bin/
10 | obj/
11 | Obj/
12 | TestResults/
13 | Nuget/Releases/*
14 |
--------------------------------------------------------------------------------
/CodeBinding.Rx.Test/CodeBinding.Rx.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 |
7 |
8 | 2.0
9 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}
10 | Library
11 | Properties
12 | CodeBinding.Rx.Test
13 | CodeBinding.Rx.Test
14 | v4.0
15 | 512
16 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
17 |
18 |
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 | 3.5
40 |
41 |
42 | False
43 | ..\packages\Rx-Main.1.0.10605\lib\Net4\System.Reactive.dll
44 |
45 |
46 |
47 |
48 | False
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | {A83663D3-6899-4E65-AC31-C076AF32197A}
58 | CodeBinding.Rx
59 |
60 |
61 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}
62 | CodeBinding.Test
63 |
64 |
65 |
66 |
67 |
68 |
69 |
76 |
--------------------------------------------------------------------------------
/CodeBinding.Rx.Test/ObservableExTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Reactive.Linq;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using CodeBinding.Test;
8 | using System.Reactive.Concurrency;
9 |
10 | namespace CodeBinding.Rx.Test
11 | {
12 | [TestClass]
13 | public class ObservableExTest
14 | {
15 | [TestMethod]
16 | public void Create_SimpleExpression()
17 | {
18 | var source = new GenericNotifyPropertyChanged();
19 | var expected = (new int[] {0, 1, 2}).ToObservable();
20 |
21 | var actual = ObservableEx.Create(() => source.Value);
22 |
23 | using (actual.SequenceEqual(expected)
24 | .ObserveOn(Scheduler.Immediate)
25 | .Subscribe(Assert.IsTrue, Assert.Fail))
26 | {
27 | source.Value = 1;
28 | source.Value = 2;
29 | }
30 | }
31 |
32 | [TestMethod]
33 | public void Create_ComplexExpression()
34 | {
35 | var source1 = new GenericNotifyPropertyChanged();
36 | var source2 = new GenericNotifyPropertyChanged();
37 | var expected = (new int[] { 0, 1, 2 }).ToObservable();
38 |
39 | var actual = ObservableEx.Create(() => source1.Value + source2.Value);
40 |
41 | bool completed = false;
42 | using (actual.Take(3).SequenceEqual(expected)
43 | .ObserveOn(Scheduler.Immediate)
44 | .Subscribe(Assert.IsTrue, e => Assert.Fail("Exception occured"), () => completed = true))
45 | {
46 | source1.Value = 1;
47 | source2.Value = 1;
48 | }
49 |
50 | Assert.IsTrue(completed, "Sequence not complete");
51 | }
52 |
53 | [TestMethod]
54 | public void Create_SimpleExpression_WrongInitialValue_CallsOnError()
55 | {
56 | var source = new GenericNotifyPropertyChanged>();
57 |
58 | var actual = ObservableEx.Create(() => source.Value.Value);
59 |
60 | bool completed = false;
61 | Exception error = null;
62 | using (actual.Subscribe(
63 | i => Assert.Fail("OnNext"),
64 | e => error = e,
65 | () => completed = true))
66 | {
67 | source.Value = new GenericNotifyPropertyChanged();
68 | source.Value.Value = 1;
69 | }
70 |
71 | Assert.IsNotNull(error, "OnError not called");
72 | Assert.IsInstanceOfType(error, typeof(NullReferenceException), "Wrong type of exception");
73 | Assert.IsFalse(completed, "Sequence complete");
74 | }
75 |
76 | [TestMethod]
77 | public void Create_SimpleExpression_WrongValueSet_CallsOnError()
78 | {
79 | var source = new GenericNotifyPropertyChanged>();
80 | source.Value = new GenericNotifyPropertyChanged();
81 | var expected = (new int[] { 0, 1 }).ToObservable();
82 | // TODO: Add this to expected sequence after SequenceEqual is switched
83 | // to somethin more elaborate
84 | //.Concat(Observable.Throw(new NullReferenceException()));
85 |
86 | var actual = ObservableEx.Create(() => source.Value.Value);
87 |
88 | bool completed = false;
89 | Exception error = null;
90 | using (actual.SequenceEqual(expected)
91 | .ObserveOn(Scheduler.Immediate).Subscribe(
92 | Assert.IsTrue,
93 | e => error = e,
94 | () => completed = true))
95 | {
96 | source.Value.Value = 1;
97 | source.Value = null;
98 | }
99 |
100 | Assert.IsNotNull(error, "OnError not called");
101 | Assert.IsInstanceOfType(error, typeof(NullReferenceException), "Wrong type of exception");
102 | Assert.IsFalse(completed, "Sequence complete");
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/CodeBinding.Rx.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("CodeBinding.Rx.Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("CodeBinding.Rx.Test")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("5a8adbf1-1bc3-4dbf-a90a-a64cb17a1f26")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/CodeBinding.Rx.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/CodeBinding.Rx (net35).csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}
9 | Library
10 | Properties
11 | CodeBinding.Rx
12 | CodeBinding.Rx
13 | v3.5
14 | 512
15 |
16 |
17 | true
18 | full
19 | false
20 | ..\bin\net35\Debug\
21 | TRACE;DEBUG;NET35
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | ..\bin\net35\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | ..\packages\Rx-Main.1.1.10425\lib\Net35\System.Reactive.dll
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}
52 | CodeBinding %28net35%29
53 |
54 |
55 |
56 |
63 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/CodeBinding.Rx.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {A83663D3-6899-4E65-AC31-C076AF32197A}
9 | Library
10 | Properties
11 | CodeBinding.Rx
12 | CodeBinding.Rx
13 | v4.0
14 | 512
15 |
16 |
17 | true
18 | full
19 | false
20 | ..\bin\net40\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | ..\bin\net40\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | False
40 | ..\packages\Rx-Main.1.0.10605\lib\Net4\System.Reactive.dll
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}
56 | CodeBinding
57 |
58 |
59 |
60 |
61 |
62 |
63 |
70 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/CodeBinding.Rx.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CodeBinding.Rx
5 | 1.0.0.0
6 | CodeBinding.Rx
7 | StanislawSwierc
8 | StanislawSwierc
9 | https://github.com/StanislawSwierc/CodeBinding
10 | false
11 | Create IObservable objects directly from lambda expressions using CodeBinding
12 | Create IObservable objects directly from lambda expressions using CodeBinding
13 | es-US
14 | wpf,binding,Rx,Reactive,extensions,Observable
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/ObservableBindingTarget.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows;
6 | using System.Reactive.Linq;
7 | using System.Diagnostics.Contracts;
8 | using System.Reactive.Disposables;
9 | using System.Windows.Data;
10 |
11 | namespace CodeBinding.Rx
12 | {
13 | public class ObservableBindingTarget : FrameworkElement, IObservable, IDisposable
14 | {
15 | private HashSet> m_Observers;
16 |
17 | public ObservableBindingTarget()
18 | {
19 | m_Observers = new HashSet>();
20 | }
21 |
22 | public T Value
23 | {
24 | get { return (T)GetValue(ValueProperty); }
25 | set { SetValue(ValueProperty, value); }
26 | }
27 |
28 | public static readonly DependencyProperty ValueProperty =
29 | DependencyProperty.Register("Value", typeof(T), typeof(ObservableBindingTarget), new UIPropertyMetadata(OnValueChanged));
30 |
31 | private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
32 | {
33 | var instance = (ObservableBindingTarget)d;
34 | lock (instance.m_Observers)
35 | {
36 | foreach (var observer in instance.m_Observers.ToArray())
37 | {
38 | observer.OnNext(instance.Value);
39 | }
40 | }
41 | }
42 |
43 | public IDisposable Subscribe(IObserver observer)
44 | {
45 | // Save observer
46 | lock (m_Observers)
47 | {
48 | m_Observers.Add(observer);
49 | }
50 |
51 | // Send current value to observer
52 | observer.OnNext(Value);
53 |
54 | return Disposable.Create(() =>
55 | {
56 | lock (m_Observers)
57 | {
58 | m_Observers.Remove(observer);
59 | }
60 | });
61 | }
62 |
63 | public void Dispose()
64 | {
65 | BindingOperations.ClearBinding(this, ObservableBindingTarget.ValueProperty);
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/ObservableEx.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Linq.Expressions;
6 | using CodeBinding;
7 | using System.Windows.Data;
8 | using System.Diagnostics.Contracts;
9 | using System.Reactive.Linq;
10 | using System.Reactive.Disposables;
11 |
12 | namespace CodeBinding.Rx
13 | {
14 | public static class ObservableEx
15 | {
16 | ///
17 | /// Creates
18 | ///
19 | ///
20 | ///
21 | ///
22 | // TODO: Change return type back to IObserbable
23 | // This will require client to save reference of the returned object
24 | public static IObservable Create(Expression> expression)
25 | {
26 | Contract.Requires(expression != null);
27 | Contract.Ensures(Contract.Result>() != null);
28 |
29 |
30 | // Create binding
31 | var binding = BindingEx.FromExpression(expression);
32 | IObservable observableConverter = null;
33 | if (binding is Binding)
34 | {
35 | var single = (Binding)binding;
36 | if (single.Converter != null)
37 | {
38 | // Create intercepting converter
39 | var converter = new ObservableValueConverter(single.Converter);
40 | // Replace original converter
41 | single.Converter = converter;
42 | observableConverter = converter;
43 | }
44 | }
45 | else if (binding is MultiBinding)
46 | {
47 | var multi = (MultiBinding)binding;
48 | // Create intercepting converter
49 | var converter = new ObservableMultiValueConverter(multi.Converter);
50 | // Replace original converter
51 | multi.Converter = converter;
52 | observableConverter = converter;
53 | }
54 | else
55 | {
56 | // Only Binding and MultiBinding classes are supported
57 | throw new InvalidOperationException("Invalid binding type");
58 | }
59 |
60 | return Observable.Create(observer =>
61 | {
62 | // Create target object
63 | var target = new ObservableBindingTarget();
64 | if (observableConverter != null)
65 | {
66 | var subscription = observableConverter.Subscribe(observer);
67 | // Binding has to be set in order to enable converter
68 | target.SetBinding(ObservableBindingTarget.ValueProperty, binding);
69 | return new CompositeDisposable(
70 | target,
71 | subscription
72 | );
73 | }
74 | else
75 | {
76 | target.SetBinding(ObservableBindingTarget.ValueProperty, binding);
77 | return new CompositeDisposable(
78 | target.Subscribe(observer),
79 | target
80 | );
81 | }
82 | }
83 | );
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/ObservableMultiValueConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Data;
6 | using System.Windows;
7 | using System.Reactive.Disposables;
8 | using System.Diagnostics.Contracts;
9 |
10 | namespace CodeBinding.Rx
11 | {
12 | internal class ObservableMultiValueConverter : ObservableValueConverterBase, IMultiValueConverter
13 | {
14 | private IMultiValueConverter m_Inner;
15 |
16 | public ObservableMultiValueConverter(IMultiValueConverter converter)
17 | {
18 | Contract.Requires(converter != null);
19 |
20 | m_Inner = converter;
21 | }
22 |
23 | #region IMultiValueConverter Implementation
24 |
25 | public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
26 | {
27 | try
28 | {
29 | object result = m_Inner.Convert(values, targetType, parameter, culture);
30 | SendNext((T)result);
31 | }
32 | catch (Exception ex)
33 | {
34 | SendError(ex);
35 | }
36 | return DependencyProperty.UnsetValue;
37 | }
38 |
39 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
40 | {
41 | throw new InvalidOperationException();
42 | }
43 |
44 | #endregion
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/ObservableValueConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Data;
6 | using System.Windows;
7 | using System.Reactive.Disposables;
8 | using System.Diagnostics.Contracts;
9 |
10 | namespace CodeBinding.Rx
11 | {
12 | internal class ObservableValueConverter : ObservableValueConverterBase, IValueConverter
13 | {
14 | private IValueConverter m_Inner;
15 |
16 | public ObservableValueConverter(IValueConverter converter)
17 | {
18 | Contract.Requires(converter != null);
19 |
20 | m_Inner = converter;
21 | }
22 |
23 | #region IValueConverter Implementation
24 |
25 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
26 | {
27 | try
28 | {
29 | object result = m_Inner.Convert(value, targetType, parameter, culture);
30 | SendNext((T)result);
31 | }
32 | catch (Exception ex)
33 | {
34 | SendError(ex);
35 | }
36 | return DependencyProperty.UnsetValue;
37 | }
38 |
39 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
40 | {
41 | throw new NotImplementedException();
42 | }
43 |
44 | #endregion
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/ObservableValueConverterBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Data;
6 | using System.Windows;
7 | using System.Reactive.Disposables;
8 | using System.Diagnostics.Contracts;
9 |
10 | namespace CodeBinding.Rx
11 | {
12 | internal abstract class ObservableValueConverterBase : IObservable
13 | {
14 | private Action m_OnNext;
15 | private Action m_OnError;
16 |
17 | protected void SendNext(T value)
18 | {
19 | var handler = m_OnNext;
20 | if (handler != null)
21 | {
22 | handler(value);
23 | }
24 | }
25 |
26 | protected void SendError(Exception error)
27 | {
28 | Action handler = null;
29 | lock (this)
30 | {
31 | // Save current subscribers
32 | handler = m_OnError;
33 |
34 | // Remove all subscribers
35 | m_OnError = null;
36 | m_OnNext = null;
37 |
38 | }
39 | if (handler != null)
40 | {
41 | handler(error);
42 | }
43 | }
44 |
45 | public IDisposable Subscribe(IObserver observer)
46 | {
47 | Contract.Requires(observer != null);
48 |
49 | // Lock to make sure m_OnNext and m_OnError are managed together
50 | lock (this)
51 | {
52 | m_OnNext += observer.OnNext;
53 | m_OnError += observer.OnError;
54 | }
55 |
56 | return Disposable.Create(() =>
57 | {
58 | // Check if handlers have been cleared already
59 | if (m_OnError != null)
60 | {
61 | lock (this)
62 | {
63 | m_OnNext -= observer.OnNext;
64 | m_OnError -= observer.OnError;
65 | }
66 | }
67 | }
68 | );
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("CodeBinding.Rx")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyProduct("CodeBinding.Rx")]
10 |
11 | // Version information for an assembly consists of the following four values:
12 | //
13 | // Major Version
14 | // Minor Version
15 | // Build Number
16 | // Revision
17 | //
18 | // You can specify all the values or you can default the Build and Revision Numbers
19 | // by using the '*' as shown below:
20 | // [assembly: AssemblyVersion("1.0.*")]
21 | [assembly: AssemblyVersion("1.1.1.0")]
22 | [assembly: AssemblyFileVersion("1.1.1.0")]
23 |
--------------------------------------------------------------------------------
/CodeBinding.Rx/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CodeBinding.Test/BindingExTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
6 | using System.Windows.Data;
7 |
8 | namespace CodeBinding.Test
9 | {
10 | [TestClass]
11 | public class BindingExTest
12 | {
13 | [TestMethod]
14 | public void FromExpression_SimpleBinding()
15 | {
16 | var target = new GenericBindingTarget();
17 | var source = new GenericNotifyPropertyChanged();
18 |
19 | BindingBase binding = BindingEx.FromExpression(() => source.Value);
20 | target.SetBinding(GenericBindingTarget.ValueProperty, binding);
21 |
22 | Assert.AreEqual(0, target.Value);
23 | source.Value = 1;
24 | Assert.AreEqual(1, target.Value);
25 | }
26 |
27 | [TestMethod]
28 | public void FromExpression_ComplexBinding()
29 | {
30 | var target = new GenericBindingTarget();
31 | var source1 = new GenericNotifyPropertyChanged();
32 | var source2 = new GenericNotifyPropertyChanged();
33 |
34 | BindingBase binding = BindingEx.FromExpression(() => source1.Value + source2.Value);
35 | target.SetBinding(GenericBindingTarget.ValueProperty, binding);
36 |
37 | Assert.AreEqual(0, target.Value);
38 | source1.Value = 1;
39 | Assert.AreEqual(1, target.Value);
40 | source2.Value = 1;
41 | Assert.AreEqual(2, target.Value);
42 | }
43 |
44 | [TestMethod]
45 | public void BindFromExpression_SimpleBinding()
46 | {
47 | var target = new GenericBindingTarget();
48 | var source = new GenericNotifyPropertyChanged();
49 |
50 | BindingEx.BindFromExpression(() => target.Value == source.Value);
51 |
52 | Assert.AreEqual(0, target.Value);
53 | source.Value = 1;
54 | Assert.AreEqual(1, target.Value);
55 | }
56 |
57 | [TestMethod]
58 | public void BindFromExpression_ComplexBinding()
59 | {
60 | var target = new GenericBindingTarget();
61 | var source1 = new GenericNotifyPropertyChanged();
62 | var source2 = new GenericNotifyPropertyChanged();
63 |
64 | BindingEx.BindFromExpression(() => target.Value == source1.Value + source2.Value);
65 |
66 | Assert.AreEqual(0, target.Value);
67 | source1.Value = 1;
68 | Assert.AreEqual(1, target.Value);
69 | source2.Value = 1;
70 | Assert.AreEqual(2, target.Value);
71 | }
72 |
73 | [TestMethod]
74 | public void BindFromExpression_SimpleBinding_DisposeSubsription_RemovesBinding()
75 | {
76 | var target = new GenericBindingTarget();
77 | var source = new GenericNotifyPropertyChanged();
78 |
79 | using (BindingEx.BindFromExpression(() => target.Value == source.Value))
80 | {
81 | Assert.AreEqual(0, target.Value);
82 | source.Value = 1;
83 | Assert.AreEqual(1, target.Value);
84 | }
85 | source.Value = 2;
86 | // Value should be reseted to 0
87 | Assert.AreEqual(0, target.Value);
88 | }
89 |
90 | [TestMethod]
91 | public void BindFromExpression_ComplexBinding_DisposeSubsription_RemovesBinding()
92 | {
93 | var target = new GenericBindingTarget();
94 | var source1 = new GenericNotifyPropertyChanged();
95 | var source2 = new GenericNotifyPropertyChanged();
96 |
97 | using (BindingEx.BindFromExpression(() => target.Value == source1.Value + source2.Value))
98 | {
99 | Assert.AreEqual(0, target.Value);
100 | source1.Value = 1;
101 | Assert.AreEqual(1, target.Value);
102 | source2.Value = 1;
103 | Assert.AreEqual(2, target.Value);
104 | }
105 | source1.Value = 2;
106 | source2.Value = 2;
107 | // Value should be reseted to 0
108 | Assert.AreEqual(0, target.Value);
109 | }
110 |
111 | [TestMethod]
112 | [ExpectedException(typeof(NullReferenceException))]
113 | public void BindFromExpression_SimpleBinding_WrongInitialValue_ThrowsExeption()
114 | {
115 | var target = new GenericBindingTarget();
116 | var source = new GenericNotifyPropertyChanged>();
117 |
118 | BindingEx.BindFromExpression(() => target.Value == source.Value.Value);
119 | }
120 |
121 | [TestMethod]
122 | [ExpectedException(typeof(NullReferenceException))]
123 | public void BindFromExpression_ComplexBinding_WrongInitialValue_ThrowsExeption()
124 | {
125 | var target = new GenericBindingTarget();
126 | var source1 = new GenericNotifyPropertyChanged();
127 | var source2 = new GenericNotifyPropertyChanged>();
128 |
129 | BindingEx.BindFromExpression(() => target.Value == source1.Value + source2.Value.Value);
130 | }
131 |
132 | [TestMethod]
133 | [ExpectedException(typeof(NullReferenceException))]
134 | public void BindFromExpression_SimpleBinding_WrongValueSet_ThrowsExeption()
135 | {
136 | var target = new GenericBindingTarget();
137 | var source = new GenericNotifyPropertyChanged>();
138 | source.Value = new GenericNotifyPropertyChanged();
139 |
140 | BindingEx.BindFromExpression(() => target.Value == source.Value.Value);
141 |
142 | Assert.AreEqual(0, target.Value);
143 | source.Value.Value = 1;
144 | Assert.AreEqual(1, target.Value);
145 | source.Value = null;
146 | }
147 |
148 | [TestMethod]
149 | [ExpectedException(typeof(NullReferenceException))]
150 | public void BindFromExpression_ComplexBinding_WrongValueSet_ThrowsExeption()
151 | {
152 | var target = new GenericBindingTarget();
153 | var source1 = new GenericNotifyPropertyChanged();
154 | var source2 = new GenericNotifyPropertyChanged>();
155 | source2.Value = new GenericNotifyPropertyChanged();
156 |
157 | BindingEx.BindFromExpression(() => target.Value == source1.Value + source2.Value.Value);
158 |
159 | Assert.AreEqual(0, target.Value);
160 | source1.Value = 1;
161 | Assert.AreEqual(1, target.Value);
162 | source2.Value.Value = 1;
163 | Assert.AreEqual(2, target.Value);
164 | source2.Value = null;
165 | }
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/CodeBinding.Test/CodeBinding.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 |
7 |
8 | 2.0
9 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}
10 | Library
11 | Properties
12 | CodeBinding.Test
13 | CodeBinding.Test
14 | v4.0
15 | 512
16 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
17 |
18 |
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | 3.5
42 |
43 |
44 |
45 |
46 |
47 |
48 | False
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}
60 | CodeBinding
61 |
62 |
63 |
64 |
71 |
--------------------------------------------------------------------------------
/CodeBinding.Test/GenericBindingTarget.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows;
6 |
7 | namespace CodeBinding.Test
8 | {
9 | public class GenericBindingTarget : FrameworkElement
10 | {
11 | public T Value
12 | {
13 | get { return (T)GetValue(ValueProperty); }
14 | set { SetValue(ValueProperty, value); }
15 | }
16 |
17 | public static readonly DependencyProperty ValueProperty =
18 | DependencyProperty.Register("Value", typeof(T), typeof(GenericBindingTarget));
19 | }
20 | }
--------------------------------------------------------------------------------
/CodeBinding.Test/GenericNotifyPropertyChanged.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.ComponentModel;
6 |
7 | namespace CodeBinding.Test
8 | {
9 | public class GenericNotifyPropertyChanged : INotifyPropertyChanged
10 | {
11 | public event PropertyChangedEventHandler PropertyChanged;
12 |
13 | private T m_Value;
14 | public T Value
15 | {
16 | get { return m_Value; }
17 | set
18 | {
19 | if ((m_Value==null && value != null) || !m_Value.Equals(value))
20 | {
21 | m_Value = value;
22 | var handler = PropertyChanged;
23 | if (handler != null)
24 | {
25 | handler(this, new PropertyChangedEventArgs("Value"));
26 | }
27 | }
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/CodeBinding.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("CodeBinding.Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("CodeBinding.Test")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("79d55bd8-a536-4a15-bd59-db27bf70bf86")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/CodeBinding.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeBinding", "CodeBinding\CodeBinding.csproj", "{5F5CB969-D0BB-4B5A-8141-1005881E23A8}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeBinding.Rx", "CodeBinding.Rx\CodeBinding.Rx.csproj", "{A83663D3-6899-4E65-AC31-C076AF32197A}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{39DCEC87-E8B5-4B39-B8C6-6A155F564E3B}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserRegistration.Rx", "Samples\UserRegistration.Rx\UserRegistration.Rx.csproj", "{C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleBinding", "Samples\SingleBinding\SingleBinding.csproj", "{0293F500-9354-4996-9780-9E8C550208E7}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeBinding (net35)", "CodeBinding\CodeBinding (net35).csproj", "{F860C2E6-ABA7-4865-B3BA-633DD4985524}"
15 | ProjectSection(ProjectDependencies) = postProject
16 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8} = {5F5CB969-D0BB-4B5A-8141-1005881E23A8}
17 | {A83663D3-6899-4E65-AC31-C076AF32197A} = {A83663D3-6899-4E65-AC31-C076AF32197A}
18 | EndProjectSection
19 | EndProject
20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeBinding.Rx (net35)", "CodeBinding.Rx\CodeBinding.Rx (net35).csproj", "{750A8DBF-A6C4-4B2C-8E11-47FC8A285347}"
21 | ProjectSection(ProjectDependencies) = postProject
22 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8} = {5F5CB969-D0BB-4B5A-8141-1005881E23A8}
23 | {A83663D3-6899-4E65-AC31-C076AF32197A} = {A83663D3-6899-4E65-AC31-C076AF32197A}
24 | EndProjectSection
25 | EndProject
26 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiBinding", "Samples\MultiBinding\MultiBinding.csproj", "{CE6FB820-220A-4BF0-B3F5-C44F06BDE459}"
27 | EndProject
28 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeBinding.Test", "CodeBinding.Test\CodeBinding.Test.csproj", "{31807B71-F1B1-4B19-A049-B60CE2A46B48}"
29 | EndProject
30 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5B8D0A04-8D11-4623-B88F-BA09C35FF2D8}"
31 | ProjectSection(SolutionItems) = preProject
32 | CodeBinding.vsmdi = CodeBinding.vsmdi
33 | Local.testsettings = Local.testsettings
34 | TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
35 | EndProjectSection
36 | EndProject
37 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeBinding.Rx.Test", "CodeBinding.Rx.Test\CodeBinding.Rx.Test.csproj", "{C4BB60C9-641A-452D-8D22-5A1340C2EC3A}"
38 | EndProject
39 | Global
40 | GlobalSection(TestCaseManagementSettings) = postSolution
41 | CategoryFile = CodeBinding.vsmdi
42 | EndGlobalSection
43 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
44 | Debug|Any CPU = Debug|Any CPU
45 | Debug|Mixed Platforms = Debug|Mixed Platforms
46 | Debug|x86 = Debug|x86
47 | Release|Any CPU = Release|Any CPU
48 | Release|Mixed Platforms = Release|Mixed Platforms
49 | Release|x86 = Release|x86
50 | EndGlobalSection
51 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
52 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
55 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
56 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Debug|x86.ActiveCfg = Debug|Any CPU
57 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
58 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Release|Any CPU.Build.0 = Release|Any CPU
59 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
60 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
61 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}.Release|x86.ActiveCfg = Release|Any CPU
62 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Debug|Any CPU.Build.0 = Debug|Any CPU
64 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
65 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
66 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Debug|x86.ActiveCfg = Debug|Any CPU
67 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Release|Any CPU.ActiveCfg = Release|Any CPU
68 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Release|Any CPU.Build.0 = Release|Any CPU
69 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
70 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
71 | {A83663D3-6899-4E65-AC31-C076AF32197A}.Release|x86.ActiveCfg = Release|Any CPU
72 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Debug|Any CPU.ActiveCfg = Debug|x86
73 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
74 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Debug|Mixed Platforms.Build.0 = Debug|x86
75 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Debug|x86.ActiveCfg = Debug|x86
76 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Debug|x86.Build.0 = Debug|x86
77 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Release|Any CPU.ActiveCfg = Release|x86
78 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Release|Mixed Platforms.ActiveCfg = Release|x86
79 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Release|Mixed Platforms.Build.0 = Release|x86
80 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Release|x86.ActiveCfg = Release|x86
81 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5}.Release|x86.Build.0 = Release|x86
82 | {0293F500-9354-4996-9780-9E8C550208E7}.Debug|Any CPU.ActiveCfg = Debug|x86
83 | {0293F500-9354-4996-9780-9E8C550208E7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
84 | {0293F500-9354-4996-9780-9E8C550208E7}.Debug|Mixed Platforms.Build.0 = Debug|x86
85 | {0293F500-9354-4996-9780-9E8C550208E7}.Debug|x86.ActiveCfg = Debug|x86
86 | {0293F500-9354-4996-9780-9E8C550208E7}.Debug|x86.Build.0 = Debug|x86
87 | {0293F500-9354-4996-9780-9E8C550208E7}.Release|Any CPU.ActiveCfg = Release|x86
88 | {0293F500-9354-4996-9780-9E8C550208E7}.Release|Mixed Platforms.ActiveCfg = Release|x86
89 | {0293F500-9354-4996-9780-9E8C550208E7}.Release|Mixed Platforms.Build.0 = Release|x86
90 | {0293F500-9354-4996-9780-9E8C550208E7}.Release|x86.ActiveCfg = Release|x86
91 | {0293F500-9354-4996-9780-9E8C550208E7}.Release|x86.Build.0 = Release|x86
92 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Debug|Any CPU.Build.0 = Debug|Any CPU
94 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
95 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
96 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Debug|x86.ActiveCfg = Debug|Any CPU
97 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Release|Any CPU.ActiveCfg = Release|Any CPU
98 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Release|Any CPU.Build.0 = Release|Any CPU
99 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
100 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Release|Mixed Platforms.Build.0 = Release|Any CPU
101 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}.Release|x86.ActiveCfg = Release|Any CPU
102 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
103 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Debug|Any CPU.Build.0 = Debug|Any CPU
104 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
105 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
106 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Debug|x86.ActiveCfg = Debug|Any CPU
107 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Release|Any CPU.ActiveCfg = Release|Any CPU
108 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Release|Any CPU.Build.0 = Release|Any CPU
109 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
110 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Release|Mixed Platforms.Build.0 = Release|Any CPU
111 | {750A8DBF-A6C4-4B2C-8E11-47FC8A285347}.Release|x86.ActiveCfg = Release|Any CPU
112 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Debug|Any CPU.ActiveCfg = Debug|x86
113 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
114 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Debug|Mixed Platforms.Build.0 = Debug|x86
115 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Debug|x86.ActiveCfg = Debug|x86
116 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Debug|x86.Build.0 = Debug|x86
117 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Release|Any CPU.ActiveCfg = Release|x86
118 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Release|Mixed Platforms.ActiveCfg = Release|x86
119 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Release|Mixed Platforms.Build.0 = Release|x86
120 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Release|x86.ActiveCfg = Release|x86
121 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459}.Release|x86.Build.0 = Release|x86
122 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
123 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Debug|Any CPU.Build.0 = Debug|Any CPU
124 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
125 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
126 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Debug|x86.ActiveCfg = Debug|Any CPU
127 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Release|Any CPU.ActiveCfg = Release|Any CPU
128 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Release|Any CPU.Build.0 = Release|Any CPU
129 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
130 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Release|Mixed Platforms.Build.0 = Release|Any CPU
131 | {31807B71-F1B1-4B19-A049-B60CE2A46B48}.Release|x86.ActiveCfg = Release|Any CPU
132 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
133 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
134 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
135 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
136 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Debug|x86.ActiveCfg = Debug|Any CPU
137 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
138 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Release|Any CPU.Build.0 = Release|Any CPU
139 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
140 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
141 | {C4BB60C9-641A-452D-8D22-5A1340C2EC3A}.Release|x86.ActiveCfg = Release|Any CPU
142 | EndGlobalSection
143 | GlobalSection(SolutionProperties) = preSolution
144 | HideSolutionNode = FALSE
145 | EndGlobalSection
146 | GlobalSection(NestedProjects) = preSolution
147 | {C8EEBF73-599A-436D-BC09-E8B99C9CB5C5} = {39DCEC87-E8B5-4B39-B8C6-6A155F564E3B}
148 | {0293F500-9354-4996-9780-9E8C550208E7} = {39DCEC87-E8B5-4B39-B8C6-6A155F564E3B}
149 | {CE6FB820-220A-4BF0-B3F5-C44F06BDE459} = {39DCEC87-E8B5-4B39-B8C6-6A155F564E3B}
150 | EndGlobalSection
151 | EndGlobal
152 |
--------------------------------------------------------------------------------
/CodeBinding.vsmdi:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CodeBinding/BindingTarget.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows;
6 | using System.Diagnostics;
7 | using System.Reflection;
8 | using System.Diagnostics.Contracts;
9 |
10 | namespace CodeBinding
11 | {
12 | internal class BindingTarget : FrameworkElement
13 | {
14 | private object m_Target;
15 | private PropertyInfo m_Property;
16 |
17 | public BindingTarget(object target, PropertyInfo property)
18 | {
19 | Contract.Requires(target != null);
20 | Contract.Requires(property != null);
21 |
22 | m_Target = target;
23 | m_Property = property;
24 | }
25 |
26 | public object Value
27 | {
28 | get { return GetValue(ValueProperty); }
29 | set { SetValue(ValueProperty, value); }
30 | }
31 |
32 | public static readonly DependencyProperty ValueProperty =
33 | DependencyProperty.Register("Value", typeof(object), typeof(BindingTarget), new UIPropertyMetadata(OnValueChanged));
34 |
35 | private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
36 | {
37 | var instance = (BindingTarget)d;
38 | instance.m_Property.SetValue(instance.m_Target, e.NewValue, null);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/CodeBinding/ClearBindingDisposable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Diagnostics.Contracts;
6 | using System.Windows.Data;
7 | using System.Windows;
8 |
9 | namespace CodeBinding
10 | {
11 | internal class ClearBindingDisposable: IDisposable
12 | {
13 | DependencyObject m_Target;
14 | DependencyProperty m_Property;
15 | BindingBase m_Binding;
16 |
17 | public ClearBindingDisposable(DependencyObject target, DependencyProperty property, BindingBase binding)
18 | {
19 | Contract.Requires(target != null);
20 | Contract.Requires(property != null);
21 | Contract.Requires(binding != null);
22 |
23 | m_Target = target;
24 | m_Property = property;
25 | m_Binding = binding;
26 | }
27 |
28 | public void Dispose()
29 | {
30 | if (m_Target == null) throw new ObjectDisposedException("ClearBindingDisposable");
31 | if (object.ReferenceEquals(BindingOperations.GetBindingBase(m_Target, m_Property), m_Binding))
32 | {
33 | BindingOperations.ClearBinding(m_Target, m_Property);
34 | }
35 | m_Target = null;
36 | m_Property = null;
37 | m_Binding = null;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/CodeBinding/CodeBinding (net35).csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {F860C2E6-ABA7-4865-B3BA-633DD4985524}
9 | Library
10 | Properties
11 | CodeBinding
12 | CodeBinding
13 | v3.5
14 | 512
15 |
16 |
17 | true
18 | full
19 | false
20 | ..\bin\net35\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | ..\bin\net35\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
53 |
--------------------------------------------------------------------------------
/CodeBinding/CodeBinding.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {5F5CB969-D0BB-4B5A-8141-1005881E23A8}
9 | Library
10 | Properties
11 | CodeBinding
12 | CodeBinding
13 | v4.0
14 | 512
15 |
16 |
17 | true
18 | full
19 | false
20 | ..\bin\net40\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | ..\bin\net40\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
56 |
--------------------------------------------------------------------------------
/CodeBinding/CodeBinding.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CodeBinding
5 | 1.0.0.0
6 | CodeBinding
7 | StanislawSwierc
8 | StanislawSwierc
9 | https://github.com/StanislawSwierc/CodeBinding
10 | false
11 | Create bindings directly from lambda expressions using CodeBinding
12 | Create bindings directly from lambda expressions using CodeBinding
13 | es-US
14 | wpf;binding
15 |
16 |
--------------------------------------------------------------------------------
/CodeBinding/ExpressionValueConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows.Data;
6 | using System.Diagnostics.Contracts;
7 | using System.Linq.Expressions;
8 |
9 | namespace CodeBinding
10 | {
11 | internal class ExpressionValueConverter : IValueConverter, IMultiValueConverter
12 | {
13 | #region Fields
14 |
15 | private Func