44using System ;
55using System . Threading ;
66using System . Windows ;
7+ using System . Windows . Controls ;
8+ using System . Windows . Markup ;
79
810using ICSharpCode . WpfDesign . Designer . Xaml ;
911using ICSharpCode . WpfDesign . XamlDom ;
@@ -14,6 +16,15 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
1416 [ TestFixture ]
1517 public class EditOperationTests : ModelTestHelper
1618 {
19+ protected override XamlLoadSettings CreateXamlLoadSettings ( )
20+ {
21+ var settings = base . CreateXamlLoadSettings ( ) ;
22+
23+ settings . TypeFinder . RegisterAssembly ( typeof ( NamespaceTests ) . Assembly ) ;
24+
25+ return settings ;
26+ }
27+
1728 Mutex mutex ;
1829
1930 [ TestFixtureSetUp ]
@@ -204,5 +215,108 @@ public void PasteSameElementMultipleTimesCheckCopiesNames()
204215 Assert . IsNotNull ( nameScope . FindName ( _name + "_Copy3" ) ) ;
205216 Assert . IsNull ( nameScope . FindName ( _name + "_Copy4" ) ) ;
206217 }
218+
219+ [ Test ]
220+ public void PasteCustomControlUsingMixedTypes ( )
221+ {
222+ DesignItem grid = CreateGridContextWithDesignSurface ( "<Button/>" ) ;
223+ DesignItem myButton = grid . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . Controls . CustomButton ( ) ) ;
224+ grid . Properties [ "Children" ] . CollectionElements . Add ( myButton ) ;
225+
226+ DesignItem extensionItem = grid . Services . Component . RegisterComponentForDesigner ( new MyExtension ( ) ) ;
227+ extensionItem . Properties [ "MyProperty1" ] . SetValue ( new Button ( ) ) ;
228+ myButton . Properties [ ICSharpCode . WpfDesign . Tests . Controls . CustomButton . TagProperty ] . SetValue ( extensionItem ) ;
229+
230+ var xamlContext = grid . Context as XamlDesignContext ;
231+ Assert . IsNotNull ( xamlContext ) ;
232+ xamlContext . XamlEditAction . Copy ( new [ ] { myButton } ) ;
233+
234+ grid = CreateGridContextWithDesignSurface ( "<Button/>" ) ;
235+ xamlContext = grid . Context as XamlDesignContext ;
236+ Assert . IsNotNull ( xamlContext ) ;
237+ var selection = grid . Services . Selection ;
238+ selection . SetSelectedComponents ( new [ ] { grid } ) ;
239+ xamlContext . XamlEditAction . Paste ( ) ;
240+
241+ string expectedXaml = "<Button />\n " +
242+ "<sdtcontrols:CustomButton>\n " +
243+ " <sdtcontrols:CustomButton.Tag>\n " +
244+ " <Controls0:MyExtension>\n " +
245+ " <Controls0:MyExtension.MyProperty1>\n " +
246+ " <Button />\n " +
247+ " </Controls0:MyExtension.MyProperty1>\n " +
248+ " </Controls0:MyExtension>\n " +
249+ " </sdtcontrols:CustomButton.Tag>\n " +
250+ "</sdtcontrols:CustomButton>\n " ;
251+
252+ AssertGridDesignerOutput ( expectedXaml , grid . Context ,
253+ "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\" " ,
254+ "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ) ;
255+ }
256+
257+ [ Test ]
258+ public void PasteCustomControlUsingStaticResource ( )
259+ {
260+ DesignItem grid = CreateGridContextWithDesignSurface ( "<Button/>" ) ;
261+
262+ DesignItemProperty resProp = grid . Properties . GetProperty ( "Resources" ) ;
263+ Assert . IsTrue ( resProp . IsCollection ) ;
264+ DesignItem exampleClassItem = grid . Services . Component . RegisterComponentForDesigner ( new ExampleClass ( ) ) ;
265+ exampleClassItem . Key = "res1" ;
266+ resProp . CollectionElements . Add ( exampleClassItem ) ;
267+
268+ DesignItem myButton = grid . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . Controls . CustomButton ( ) ) ;
269+ grid . Properties [ "Children" ] . CollectionElements . Add ( myButton ) ;
270+
271+ myButton . Properties [ TextBox . TagProperty ] . SetValue ( new StaticResourceExtension ( ) ) ;
272+ myButton . Properties [ TextBox . TagProperty ] . Value . Properties [ "ResourceKey" ] . SetValue ( "res1" ) ;
273+
274+ // Verify xaml document to be copied
275+ string expectedXaml = "<Grid.Resources>\n " +
276+ " <Controls0:ExampleClass x:Key=\" res1\" />\n " +
277+ "</Grid.Resources>\n " +
278+ "<Button />\n " +
279+ "<sdtcontrols:CustomButton Tag=\" {StaticResource ResourceKey=res1}\" />\n " ;
280+
281+ AssertGridDesignerOutput ( expectedXaml , grid . Context ,
282+ "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\" " ,
283+ "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ) ;
284+
285+ var xamlContext = grid . Context as XamlDesignContext ;
286+ Assert . IsNotNull ( xamlContext ) ;
287+ xamlContext . XamlEditAction . Copy ( new [ ] { myButton } ) ;
288+
289+ grid = CreateGridContextWithDesignSurface ( "<Button/>" ) ;
290+
291+ resProp = grid . Properties . GetProperty ( "Resources" ) ;
292+ Assert . IsTrue ( resProp . IsCollection ) ;
293+ exampleClassItem = grid . Services . Component . RegisterComponentForDesigner ( new ExampleClass ( ) ) ;
294+ exampleClassItem . Key = "res1" ;
295+ resProp . CollectionElements . Add ( exampleClassItem ) ;
296+
297+ xamlContext = grid . Context as XamlDesignContext ;
298+ Assert . IsNotNull ( xamlContext ) ;
299+ var selection = grid . Services . Selection ;
300+ selection . SetSelectedComponents ( new [ ] { grid } ) ;
301+ xamlContext . XamlEditAction . Paste ( ) ;
302+
303+ AssertGridDesignerOutput ( expectedXaml , grid . Context ,
304+ "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\" " ,
305+ "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ) ;
306+ }
307+ }
308+
309+ public class MyExtension : MarkupExtension
310+ {
311+ public MyExtension ( )
312+ {
313+ }
314+
315+ public override object ProvideValue ( IServiceProvider serviceProvider )
316+ {
317+ return null ;
318+ }
319+
320+ public object MyProperty1 { get ; set ; }
207321 }
208322}
0 commit comments