@@ -253,6 +253,57 @@ public void PasteCustomControlUsingMixedTypes()
253253 "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\" " ,
254254 "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ) ;
255255 }
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+ }
256307 }
257308
258309 public class MyExtension : MarkupExtension
0 commit comments