简体   繁体   中英

How to flag a default event for a user control in WinCE Compact Framework 3.5

so after so many years I'm still writing program for Wince in C# with .NET CF 3.5 and I have a custom control with self-defined events based on WinForm controls. I just don't seem to find the [DefaultEvent] attribute.

I assume this can somehow be done because without this attribute how would people create custom control with default event for double-clicking in designer back at the time? I'm using VS2008. Any ideas?

Thanks.

As far as I know, the designer (that obviously does not run on .NET CF) uses the controls from the full framework under the hood. There is some sort of mapping that applies custom attributes for .NET CF using a DesigntimeAttributes.xmta . This way they did not have to port all the designers to CF.

This link shows how you can generate a DesigntimeAttributes.xmta using the "View class diagram" feature, and this link has some additional information about editing the file.

In short, you add a DesigntimeAttributes.xmta file to your project with something like:

<Classes xmlns="http://schemas.microsoft.com/VisualStudio/2004/03/SmartDevices/XMTA.xsd">
  <Class Name="MyProject.MyCustomControl">
    <DefaultEvent>MyDefaultEvent</DefaultEvent>
  </Class>
</Classes>

As for the genasm.exe error you were having, this link contains information and the steps to reproduce it. I created a method that returns an SqlCeCommand (I assume that's what your CommandCollection property returns) and get the same error. When I change that method to return DbCommand instead, the error disappears.

If you can get away with replacing every SqlCeCommand to DbCommand (and all other types from the family) you might want to go there - but the workarounds seem quite heavy for just adding a default event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM