@@ -200,6 +200,57 @@ public void PasteCustomControlUsingMixedTypes()
200200 "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\" " ,
201201 "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ) ;
202202 }
203+
204+ [ Test ]
205+ public void PasteCustomControlUsingStaticResource ( )
206+ {
207+ DesignItem grid = CreateGridContextWithDesignSurface ( "<Button/>" ) ;
208+
209+ DesignItemProperty resProp = grid . Properties . GetProperty ( "Resources" ) ;
210+ Assert . IsTrue ( resProp . IsCollection ) ;
211+ DesignItem exampleClassItem = grid . Services . Component . RegisterComponentForDesigner ( new ExampleClass ( ) ) ;
212+ exampleClassItem . Key = "res1" ;
213+ resProp . CollectionElements . Add ( exampleClassItem ) ;
214+
215+ DesignItem myButton = grid . Services . Component . RegisterComponentForDesigner ( new ICSharpCode . WpfDesign . Tests . Controls . CustomButton ( ) ) ;
216+ grid . Properties [ "Children" ] . CollectionElements . Add ( myButton ) ;
217+
218+ myButton . Properties [ TextBox . TagProperty ] . SetValue ( new StaticResourceExtension ( ) ) ;
219+ myButton . Properties [ TextBox . TagProperty ] . Value . Properties [ "ResourceKey" ] . SetValue ( "res1" ) ;
220+
221+ // Verify xaml document to be copied
222+ string expectedXaml = "<Grid.Resources>\n " +
223+ " <Controls0:ExampleClass x:Key=\" res1\" />\n " +
224+ "</Grid.Resources>\n " +
225+ "<Button />\n " +
226+ "<sdtcontrols:CustomButton Tag=\" {StaticResource ResourceKey=res1}\" />\n " ;
227+
228+ AssertGridDesignerOutput ( expectedXaml , grid . Context ,
229+ "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\" " ,
230+ "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ) ;
231+
232+ var xamlContext = grid . Context as XamlDesignContext ;
233+ Assert . IsNotNull ( xamlContext ) ;
234+ xamlContext . XamlEditAction . Copy ( new [ ] { myButton } ) ;
235+
236+ grid = CreateGridContextWithDesignSurface ( "<Button/>" ) ;
237+
238+ resProp = grid . Properties . GetProperty ( "Resources" ) ;
239+ Assert . IsTrue ( resProp . IsCollection ) ;
240+ exampleClassItem = grid . Services . Component . RegisterComponentForDesigner ( new ExampleClass ( ) ) ;
241+ exampleClassItem . Key = "res1" ;
242+ resProp . CollectionElements . Add ( exampleClassItem ) ;
243+
244+ xamlContext = grid . Context as XamlDesignContext ;
245+ Assert . IsNotNull ( xamlContext ) ;
246+ var selection = grid . Services . Selection ;
247+ selection . SetSelectedComponents ( new [ ] { grid } ) ;
248+ xamlContext . XamlEditAction . Paste ( ) ;
249+
250+ AssertGridDesignerOutput ( expectedXaml , grid . Context ,
251+ "xmlns:Controls0=\" clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\" " ,
252+ "xmlns:sdtcontrols=\" http://sharpdevelop.net/WpfDesign/Tests/Controls\" " ) ;
253+ }
203254 }
204255
205256 public class MyExtension : MarkupExtension
0 commit comments