3

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.

Lionet Chen
  • 832
  • 11
  • 26

1 Answers1

1

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.

C.Evenhuis
  • 25,996
  • 2
  • 58
  • 72
  • Hi Evenhuis, after creating a XMTA file I got an error `genasm.exe(1) : error There was an error initializing MobileScan.dbDataSetTableAdapters.dbTableAdapter.get_CommandCollection. Could not load file or assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.` Deleting the XMTA file removes the error. Is it an known issue here? P.S. If I change the Build Action from `None` to `Content` then no error but the DefaultEvent didn't take effect when the control on double click – Lionet Chen Jul 20 '16 at 23:10
  • @LionetChen I can't think of a reason why it would fail to load an assembly _because_ of the XMTA :( – C.Evenhuis Jul 21 '16 at 06:25
  • Someone ran into the same issue: https://social.msdn.microsoft.com/Forums/en-US/887362ed-4ab1-4671-a485-e86321f6bb62/genasm-error-message-when-adding-designtimeattributesxmta-to-my-project?forum=windowsmobiledev – C.Evenhuis Jul 21 '16 at 07:11
  • @LionetChen I can reproduce the issue here as well, updated the answer. – C.Evenhuis Jul 21 '16 at 07:35
  • C.Evenhuis, thanks for your great tip. I've solved the problem by creating a ControlLibrary project and put all my user controls in it then tweak with the DesignTimeAttributes.xmta there. And I add that project as a reference to my main project. Now everything works and I don't have to go around changing god knows how many codes. Also those commands are generated by the DataSource tool box so not really my place to modify. – Lionet Chen Jul 21 '16 at 09:12