Recently, I started to develop components to meet the company's business and technical needs. At the same time, I am planning the component development route to prepare technical reserves for the company's next-generation products.
On New Year's Day holiday, I watched component development in Windows 8. In addition to the traditional WPF, Windows form, Silverlight, and ASP. NET components, I also added a new winrt component.
Winrt = Windows Runtime is a new framework introduced by Windows 8. It is designed to provide a language-independent and highly intelligent platform for development on Windows platforms.
Not to replace. net, Win32, etc., but to be compiled for different languagesProgramProvides unified support, especially for Metro-style programs.
Download test code
I. Preparations
Install development tools such as Windows 8 Developer Preview and VS 11 Developer Preview.
When installing Win8, be sure to use the Windows Live ID to log on. If you do not have an account, you can register one first. Otherwise, the metro program cannot be run later.
Install Win8 and update the graphics card driver. AMD officially provides the Windows 8 Driver. NVIDIA uses the win7 driver to ensure the resolution is 1024x768 or higher.
VS 11 we recommend that you uninstall the built-in Express version and install the full-featured Developer Preview version.
In addition, SQL Server 2012 RC0 has been released. We recommend that you install it.
2. Start Development
2.1 create a Windows Metro Style Class Library Project:
2.2 Add a class:
2.3 write a buttonx, inherited from the button:
Most components of winrt are located inWindows. UI. XAML. ControlsNamespace:
2.4. winrt is similar to the WPF and Silverlight components. I will see the gourd painting and add the following in buttonx:Code:
2.5 create a new themes folder and add the generic. XAML file to it. Because there is no resource dictionary, add a page and delete the background code:
UseResourcedictionaryTo load multiple components.
2.6 AddButtonx. XAMLWrite the following code:
Xmlns:Winrt= "CLR-namespace: Brooks. customercontrol. winrt"
To add a prefix reference.
2.7 If compilation is performed directly, an error is prompted:
Google hasn't found a solution for half a day. simply copy the missing files to the corresponding location. I didn't expect it.
In this way, the simplest buttonx component is complete. Create a project to test it.
2.8 create a Windows Metro style application project:
Add project reference:
2.9 Add a blank page named test. XAML. At the beginning, I reference the component as follows:
Xmlns:Winrt= "Brooks. customercontrol. winrt; Assembly = Brooks. customercontrol. winrt"
Errors always occur during running,ButtonxIs an unknown type.
Later, I used ide to automatically add references. It was originally using and does not need to be added.Assembly.
Xmlns:Winrt= "Using: Brooks. customercontrol. winrt"
In this way, you can:
2.10 write the following code in its click event. Click buttonx to increase the button width by 5:
2.11. After running, you can see the effect:
If you log on to Windows 8 using a local account or the resolution is lower than 1024x768, the following error may occur:
This seems to be a permission issue, which many people have encountered on the Internet.
After successful running, the effect is as follows:
You can also see this program in the navigation of Metro:
2.12. About. winmd
Windows 8 introduces a new component winmd for winrt applications. The file extension is. winmd. It is essentially a DLL, that is, the PE format.
Windows 8 winmd components are located at: C: \ Program Files (x86) \ Windows kits \ 8.0 \ Windows metadata by default.
You can use the hexadecimal editor to open and view:
You can also decompile it directly:
The project type of my custom components is still class library. If it is changed to winmd, an error occurs:
If a friend has solved this problem, please let us know.
Summary:
The release of Windows 8 will expand its tentacles to tablet and handheld devices. As a basic solution, winrt is worth noting.
Because Windows 8 is still in an early stage, the development environment is still not perfect. I believe that with the official version approaching, the above problems will be solved one by one.