{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/Win2D/issues/362","repository_url":"https://api.github.com/repos/Microsoft/Win2D","labels_url":"https://api.github.com/repos/Microsoft/Win2D/issues/362/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/Win2D/issues/362/comments","events_url":"https://api.github.com/repos/Microsoft/Win2D/issues/362/events","html_url":"https://github.com/Microsoft/Win2D/issues/362","id":159432333,"number":362,"title":"CanvasControl.Content UIElement does not compose with the canvas drawing","user":{"login":"dtaylorus","id":2476671,"avatar_url":"https://avatars.githubusercontent.com/u/2476671?v=3","gravatar_id":"","url":"https://api.github.com/users/dtaylorus","html_url":"https://github.com/dtaylorus","followers_url":"https://api.github.com/users/dtaylorus/followers","following_url":"https://api.github.com/users/dtaylorus/following{/other_user}","gists_url":"https://api.github.com/users/dtaylorus/gists{/gist_id}","starred_url":"https://api.github.com/users/dtaylorus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtaylorus/subscriptions","organizations_url":"https://api.github.com/users/dtaylorus/orgs","repos_url":"https://api.github.com/users/dtaylorus/repos","events_url":"https://api.github.com/users/dtaylorus/events{/privacy}","received_events_url":"https://api.github.com/users/dtaylorus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-09T15:08:46Z","updated_at":"2016-06-09T15:08:46Z","closed_at":null,"body":"\r\nIf I set the Content property of CanvasControl, I expect to be able to compose the specified child UIElement layered above and/or below the Win2D drawing primitives.\r\n\r\nFor example, I expect to be able to compose a filled rectangle with the text \"Hello, World!\" using the following code:\r\n\r\n    var canvas = new CanvasControl();\r\n    canvas.Draw += CanvasControl_Draw;\r\n    canvas.Content = new TextBlock() { Text = \"Hello, World!\" };\r\n    \r\n    void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)\r\n    {\r\n        args.DrawingSession.FillRectangle(0, 0, this.ActualWidth, this.ActualHeight, Colors.CornflowerBlue);\r\n    }\r\n\r\nInstead, the TextBlock completely replaces the filled rectangle drawing, which looks like it is drawn to an image that no longer in the visual tree.\r\n\r\nThis view composition functionality is supported by the iOS UIView class and the Android View class, which both have a virtual Draw method that can be overridden to enable custom canvas drawing primitives to be composed with any view.\r\n\r\nThis is a simple and powerful method for customizing the look of an existing UI control that has been sorely missed on the Windows XAML platform and makes some cross-platform UI scenarios extremely difficult on Windows.\r\n\r\nFor example, the [NControl](https://github.com/chrfalch/NControl) library takes advantage of this composition functionality to enable cross-platform custom controls on Android and iOS using [NGraphics](https://github.com/praeclarum/NGraphics) and [Xamarin.Forms](https://www.xamarin.com/forms), but has to resort to extremely inefficient methods of layering, removing, and re-layering child controls for each Draw update on the Windows platform.\r\n\r\nIdeally, Windows XAML would have this primitive canvas drawing functionality built-in to the UIElement base class, like Android and iOS, but thanks to Win2D there is now at least the potential of using the CanvasControl as an alternative base class to finally have similar functionality on the Windows platform.\r\n\r\nI may be able to create this functionality with the existing CanvasControl by implementing a UserControl subclass with a private Grid panel that sandwiches the control content UIElement between two CanvasControl instances (one each for background and foreground drawing), but this would essentially turn every control into five controls, which seems very inefficient.\r\n\r\nPlease consider enabling an efficient implementation of this custom control composition functionality in Win2D to allow Windows to become a first-class citizen in the world of cross-platform owner-drawn controls.\r\n\r\nThanks!\r\n\r\nP.S. I'd also love some feedback on the impact of potentially having an entire UI composed of these CanvasControl objects. I have no idea how much overhead is introduced by each instance of this control."}}
{"actor":{"display_login":"dtaylorus"}}