Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an alternate to TemplatePartAttribute in UWP?

It took me a bit of time to discover this, but designer-specific attributes like TemplatePart are now causing issues with the release build of my UWP application.

Applying this attribute to your controls is using reflection.

[TemplatePart(Name = PART_Panel, Type = typeof(Panel))]
public class MyAwesomeControl : Control
{
   ...
}

And build output gives me this:

warning : Type 'Windows.UI.Xaml.Controls.Panel' was not included in compilation, but was referenced in type 'MyAwesomeControl'. There may have been a missing assembly.

If you want the build to work, I have to exclude that attribute. However, that defeats the purpose of a control library. Users of my library will not know that a Panel with the name PART_Panel is required in the template of MyAwesomeControl.

Is there a solution to this? Do I have to enable reflection for that type just to allow design-time attributes through?

I am aware of the rd.xml file that can be embedded in a project. However, if a <Type Name="Windows.UI.Xaml.Controls.Panel" ... /> is included, doesn't that mean that I'm telling the compiler to exclude that panel from .Net Native optimization?

like image 801
Laith Avatar asked Nov 19 '25 16:11

Laith


1 Answers

This is an unfortunate bug in the version of the .Net Native tools (ilc.exe) that you're running on. This attribute is supported properly as of the Update 1 release of Visual Studio. You can get the RC here: https://www.visualstudio.com/en-us/news/vs2015-update1-vs.aspx

You can safely ignore that warning if you're stuck using older tools.

like image 53
MattWhilden Avatar answered Nov 21 '25 06:11

MattWhilden