|
17 | 17 | // DEALINGS IN THE SOFTWARE. |
18 | 18 |
|
19 | 19 | using System; |
| 20 | +using System.Windows; |
| 21 | +using System.Windows.Controls; |
| 22 | +using System.Windows.Data; |
20 | 23 | using NUnit.Framework; |
21 | 24 | using System.Windows.Markup; |
22 | 25 | using ICSharpCode.WpfDesign.XamlDom; |
@@ -118,6 +121,79 @@ public void TestQuotedPathWithCommasAndSpaces() |
118 | 121 | { |
119 | 122 | TestMarkupExtension("Content=\"{t:String '" + PathWithCommasAndSpaces + "'}\""); |
120 | 123 | } |
| 124 | + |
| 125 | + [Test] |
| 126 | + public void TestMultiBinding() |
| 127 | + { |
| 128 | + string xaml = @" |
| 129 | +<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" |
| 130 | + xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""> |
| 131 | + <TextBox> |
| 132 | + <MultiBinding> |
| 133 | + <MultiBinding.Converter> |
| 134 | + <t:MyMultiConverter /> |
| 135 | + </MultiBinding.Converter> |
| 136 | + <Binding Path=""SomeProperty"" /> |
| 137 | + </MultiBinding> |
| 138 | + </TextBox> |
| 139 | +</Window>"; |
| 140 | + |
| 141 | + TestLoading(xaml); |
| 142 | + |
| 143 | + TestWindowMultiBinding((Window)XamlReader.Parse(xaml)); |
| 144 | + |
| 145 | + var doc = XamlParser.Parse(new StringReader(xaml)); |
| 146 | + |
| 147 | + TestWindowMultiBinding((Window)doc.RootInstance); |
| 148 | + } |
| 149 | + |
| 150 | + |
| 151 | + void TestWindowMultiBinding(Window w) |
| 152 | + { |
| 153 | + var textBox = (TextBox)w.Content; |
| 154 | + |
| 155 | + var expr = BindingOperations.GetMultiBindingExpression(textBox, TextBox.TextProperty); |
| 156 | + Assert.IsNotNull(expr); |
| 157 | + |
| 158 | + var converter = expr.ParentMultiBinding.Converter as MyMultiConverter; |
| 159 | + Assert.IsNotNull(converter); |
| 160 | + |
| 161 | + Assert.AreEqual(expr.ParentMultiBinding.Bindings.Count, 1); |
| 162 | + } |
| 163 | + |
| 164 | + [Test] |
| 165 | + public void TestPriorityBinding() |
| 166 | + { |
| 167 | + string xaml = @" |
| 168 | +<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" |
| 169 | + xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""> |
| 170 | + <TextBox> |
| 171 | + <PriorityBinding> |
| 172 | + <Binding Path=""SomeProperty"" /> |
| 173 | + <Binding Path=""OtherProperty"" /> |
| 174 | + </PriorityBinding> |
| 175 | + </TextBox> |
| 176 | +</Window>"; |
| 177 | + |
| 178 | + TestLoading(xaml); |
| 179 | + |
| 180 | + TestWindowPriorityBinding((Window)XamlReader.Parse(xaml)); |
| 181 | + |
| 182 | + var doc = XamlParser.Parse(new StringReader(xaml)); |
| 183 | + |
| 184 | + TestWindowPriorityBinding((Window)doc.RootInstance); |
| 185 | + } |
| 186 | + |
| 187 | + |
| 188 | + void TestWindowPriorityBinding(Window w) |
| 189 | + { |
| 190 | + var textBox = (TextBox)w.Content; |
| 191 | + |
| 192 | + var expr = BindingOperations.GetPriorityBindingExpression(textBox, TextBox.TextProperty); |
| 193 | + Assert.IsNotNull(expr); |
| 194 | + |
| 195 | + Assert.AreEqual(expr.ParentPriorityBinding.Bindings.Count, 2); |
| 196 | + } |
121 | 197 |
|
122 | 198 | // [Test] |
123 | 199 | // public void Test10() |
@@ -177,4 +253,19 @@ public override object ProvideValue(IServiceProvider serviceProvider) |
177 | 253 | return null; |
178 | 254 | } |
179 | 255 | } |
| 256 | + |
| 257 | + public class MyMultiConverter : IMultiValueConverter |
| 258 | + { |
| 259 | + #region IMultiValueConverter implementation |
| 260 | + public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
| 261 | + { |
| 262 | + return System.Windows.DependencyProperty.UnsetValue; |
| 263 | + } |
| 264 | + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) |
| 265 | + { |
| 266 | + throw new NotImplementedException(); |
| 267 | + } |
| 268 | + #endregion |
| 269 | + |
| 270 | + } |
180 | 271 | } |
0 commit comments