Building Custom Controls on top of WinRT in C#
-
Thursday, September 15, 2011 5:07 PMI note that in the Visual Studio 11 express edition developer preview, there is a template for creating a custom control in C++ but not C#. Does that mean that custom controls now need to be developed in C++? Is there (or will there) be a way to do this in C#?
Cameron Peters
All Replies
-
Thursday, September 15, 2011 8:43 PM
Hi Cameron. The template in C++ is a component, not a control. The same thing is in C# as well (class library). You would need to add a resource dictionary (generic.xaml) for which we don't have an item template for in this release, but it is the same as the Silverlight one. We've got a few questions on this area, so as soon as I can I'll try to post a sample of how to do this.
Short answer: there is a way to do this in C# and it will improve over time.
- Proposed As Answer by Tim Heuer [MSFT]Microsoft Employee Thursday, September 15, 2011 8:44 PM
- Marked As Answer by Cameron Peters - Trilogy Software Thursday, September 15, 2011 9:45 PM
- Unmarked As Answer by Cameron Peters - Trilogy Software Friday, September 16, 2011 6:51 PM
-
Thursday, September 15, 2011 8:52 PM
Tim,
Thanks... I look forward to some examples. Does that mean we can descend from the WinRT implemented Panel control in C#? How will the dependency properties work across this boundary. How is memory handled? Does WinRT use a malloc / release model or is WinRT memory somehow garbage collected?
... looks like my decision not to registor for Build until the agenda got posted was a mistake.... :( I have lots of questions that may have been answered in the chalk talks but sadly those videos won't be posted...
~ Cameron
Cameron Peters -
Friday, September 16, 2011 4:26 PM
Yes, you can descend from the WinRT implemented Panel in C# (and for example override MeasureOverride), you can descend from Control (and for example override OnApplyTemplate), etc.
WinRT objects control their lifetime with AddRef/Release, but when you're programming in C# you don't see it; GC takes care of the ref counting.
Dependency properties go across the boundary when you call DependencyObject.SetValue/GetValue etc. You can pass a WinRT object as a property value or a non-WinRT object. From you C# code you don't see the difference.
- Mike
- Marked As Answer by Cameron Peters - Trilogy Software Friday, September 16, 2011 6:51 PM
-
Friday, September 16, 2011 6:52 PM
Mike --
Thanks... this is exactly what I needed to know. How is there a performance hit to crossing the boundary?
~ Cameron
Cameron Peters -
Tuesday, September 20, 2011 4:32 AM
Hi Tim
If I create a WinRT control using C#, can I use it in 'flavors' of Metro apps (C++, HTML, C#, VB)?
Or are there differebt 'kinds' of WinRT controls, one for C#/VB/C++ and one for HTML/js?
Probably a dumb question, but I would love to develop only one set of controls and be able to use them in all kinds of apps...
bernardo castilho -
Tuesday, September 20, 2011 2:39 PM
UI components can be shared between amongst languages that use XAML for rendering (C++/VB/C#) but cannot be shared with the apps that use HTML for rendering. If you create WinRT components that don't have UI-related dependencies, they can also be shared with HTML/JS apps.
Robert Levy- Proposed As Answer by Robert_Levy Tuesday, September 20, 2011 2:39 PM
-
Thursday, November 03, 2011 4:07 PMwhere is the sample?
-
Thursday, December 29, 2011 12:59 PM
"... I'll try to post a sample of how to do this..."
I desperately need a sample of how to create a custom control in C#. Any help would be appreciated.
-
Monday, July 23, 2012 8:41 PMHere is the source for two relatively simple WinRT C#/XAML custom controls: http://panview.codeplex.com/ and http://charmflyout.codeplex.com/.
John Michael Hauck


