X A M L eXtensible Application Markup Language Width="100" Height="30" Background="AliceBlue"> private void Button1_Click(object sender, RoutedEventArgs e) { // Turn screen background red this.LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0)); }

Download Report

Transcript X A M L eXtensible Application Markup Language Width="100" Height="30" Background="AliceBlue"> private void Button1_Click(object sender, RoutedEventArgs e) { // Turn screen background red this.LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0)); }

X
A
M
L
eXtensible
Application
Markup
Language
<Grid>
<TextBlock FontSize="48" Text="Hello world" />
</Grid>
<Grid x:Name="LayoutRoot" Background="Black">
<Button x:Name="Button1" Click="Button1_Click" Content="Click Me!"
Width="100" Height="30" Background="AliceBlue"></Button>
</Grid>
private void Button1_Click(object sender, RoutedEventArgs e)
{
// Turn screen background red
this.LayoutRoot.Background = new
SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));
}
// Locate the button in the object tree
IXRButtonPtr pButton;
pVisualHost->GetRootElement(&pRootElement);
FindName(pRootElement, L"Button1", IID_IAXButton, &pButton);
// Add OnClick Event handler
pButton->AddClickEventHandler(CreateDelegate(pEventHandler,
&EventHandler::OnButtonClick));
…
class EventHandler
{
public:
HRESULT OnButtonClick(IAXDependencyObject* pSender,
AXEventArgs* pArgs)
{
// Do something when the user clicks the button…
}
}
http://geekswithblogs.net/WindowsEmbeddedCookbook/archive/2009/11/11/xaml2cpp.aspx
C:\Projects\SWETest> xaml2cpp Page.xaml
XAML2CPP version 1.0.2.0
C:\Projects\SWETest>
// ==========================================================================
// WinMain – Application control logic for the native SWE app
// ==========================================================================
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hInstPrev*/,
LPWSTR /*lpCmdLine*/, int /*nShowCmd*/)
{
App AppInstance;
HRESULT hr = AppInstance.Initialize(hInstance);
if(SUCCEEDED(hr))
{
hr = AppInstance.Run();
}
return AppInstance.GetWinMainResultCode();
}
HRESULT MainPage::OnLoaded(__in IXRDependencyObject* pRoot)
{
UNREFERENCED_PARAMETER(pRoot);
HRESULT hr = InitializeComponent();
// Add calls to FindName or Add___EventHandler() methods after this comment.
if (m_pMyButton)
{
m_pMyButton->AddClickEventHandler(
CreateDelegate(this, &MainPage::OnButtonClick));
}
return hr;
} // OnLoaded
// ===========================================================================
// OnButtonClick
// Description: Event handler implementation
//
// Parameters: pSender - The dependency object that raised the click event.
//
pArgs - Event specific arguments.
// ===========================================================================
HRESULT MainPage::OnButtonClick (IXRDependencyObject* pSender,
XRMouseButtonEventArgs* pArgs)
{
HRESULT hr = E_NOTIMPL;
if ((NULL == pSender) || (NULL == pArgs))
{
hr = E_INVALIDARG;
}
return hr;
}
Page
Click Me
#ifdef SWENATIVE_EXPORTS
#define SWENATIVE_API __declspec(dllexport)
#else
#define SWENATIVE_API __declspec(dllimport)
#endif
extern
extern
extern
extern
"C"
"C"
"C"
"C"
SWENATIVE_API
SWENATIVE_API
SWENATIVE_API
SWENATIVE_API
int
int
int
int
RunXamlUI();
GetControlText(LPWSTR lName, BSTR* pValue);
SetControlText(LPWSTR lName, LPWSTR lValue);
StartStoryboard(LPWSTR lName);
HINSTANCE hDll;
static App *app;
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
hDll = (HINSTANCE)hModule; // Save the HINSTANCE handle of the dll
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break; }
return TRUE;
}
extern "C" SWENATIVE_API int RunXamlUI() // Start the XAML UI
{
app = new App();
if (FAILED(app->Initialize(hDll))) return -1; // Call Initialize passing HINSTANCE of the dll
if (FAILED(app->Run())) return -1;
// Run doesn’t return until XAML UI exits
return 0;
}
using System.Runtime.InteropServices;
namespace ManagedConsoleHost {
class Program
{
[DllImport("SWEnative.dll")]
static extern int RunXamlUI();
static void Main(string[] args)
{
// Call the native method to run the UI
RunXamlUI();
}
}
}
// This in SWEnative.h. Callback function prototype
typedef void (CALLBACK *CLICKCALLBACK)(LPWSTR lParam);
// Modify the RunXamlUI function to accept a parameter that specifies the callback
extern "C" SWENATIVE_API int RunXamlUI(CLICKCALLBACK callback);
extern "C" SWENATIVE_API int RunXamlUI(CLICKCALLBACK callback)
{
app = new App();
app->ClickCallback = callback; // Save the callback function for later
…
// This in MainPage.cpp: Declare event handler in UI class
// ============================================================================
// OnButtonClick
//
// Description: Event handler implementation
// Parameters: pSender - The dependency object that raised the click event.
//
pArgs - Event specific arguments.
// ============================================================================
HRESULT MainPage::OnButtonClick (IXRDependencyObject* pSender, XRMouseButtonEventArgs* pArgs)
{
if (App::ClickCallback != NULL)
{
BSTR controlName;
pSender->GetName(&controlName);
// Call the callback function, passing the name of the control raising the event
App::ClickCallback((LPWSTR)controlName);
}
return S_OK;
}
using System.Runtime.InteropServices;
namespace SWEManagedHost
{
class Program
{
[DllImport("SWEnative.dll")]
static extern int RunXamlUI(ClickCallBackDelegate cbdele);
// Declare a delegate that matches the signature of the native CALLBACK
public delegate void ClickCallBackDelegate(StringBuilder msg);
// Make this a static - to make sure
// that the function pointer doesn't get garbage collected later on
static ClickCallBackDelegate cbdele;
// Continued…
// Continued…
static void Main(string[] args)
{
// Declare the delegate to the callback function
cbdele = new ClickCallBackDelegate(SilverlightClickEventHandler);
// Call the native method to start up the UI, passing the delegate
RunXamlUI(cbdele);
}
// Event handler executes when called from native
private void SilverlightClickEventHandler(StringBuilder msg)
{
MessageBox.Show("Click from Silverlight, control name: " + msg.ToString);
}
}
Page
Click Me
Get
Start/Stop
Set
Model – View – Presenter
design pattern
Native
Managed
View Framework
App code
public class SampleApplicationView : SLBaseView
{
private Appamundi.Windows.Controls.Button helloButton = null;
private Appamundi.Windows.Controls.TextBox txtForename = null;
private Appamundi.Windows.Controls.TextBox txtSurname = null;
public SampleApplicationView(BaseShell shell):base(shell)
{
InitializeView();
// Create control objects that are proxies for those created in XAML
helloButton = new Appamundi.Windows.Controls.Button("btnSayHello", this);
txtForename = new Appamundi.Windows.Controls.TextBox("txtForename", this);
txtSurname = new Appamundi.Windows.Controls.TextBox("txtSurname", this);
helloButton.Click += new EventHandler(
(s, a) =>
{
txtForename.Text = "Vladimir"; // Set a control property
MessageBox.Show("Hello " + txtForename.Text + " " + txtSurname.Text);
});
}
}
<UserControl
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns:xr="clr-namespace:EmbeddedXamlRuntime"
x:Class="SimpleSLapp.Page"
Width="640" Height="480" Background="#FFC42929">
<Grid x:Name="LayoutRoot">
<Button Height="99" Margin="176,44,216,0" VerticalAlignment="Top"
Content="Button" Click="OnButtonClick" Background="#FF32A625"
x:Name="MyButton"/>
<TextBox Height="45" Margin="176,168,237,0" VerticalAlignment="Top"
Text="TextBox" TextWrapping="Wrap" Background="#FFDACB19"
x:Name="MyTextBox"/>
<xr:Win32Control x:Name="WinFormTest"
Height="200" Width="200"
HorizontalAlignment="Left" Margin="203,0,237,23“
VerticalAlignment="Bottom" />
</Grid>
</UserControl>
int ShowWin32Control(HWND win32Handle)
{
HRESULT retcode;
IXRWin32ControlPtr pIWin32Ctl;
// Find the placeholder IXRWin32Control control in the Silverlight object tree
if (FAILED(retcode=root->FindName(L"WinFormTest",&pIWin32Ctl))) return retcode;
// Swap the handle of the found control with the one of the Win32 control
pIWin32Ctl->SetHandle(win32Handle, false);
// The Win32 control is now represented in the visual tree
// and is integrated with the on-screen layout of peer controls in the window.
// activate the visual host window and repaint the changed portion
HWND HostWindow = NULL;
GetVisualHost()->GetContainerHWND(&HostWindow);
ShowWindow(HostWindow, SW_SHOW);
UpdateWindow(HostWindow);
return 0;
}
public partial class Form1 : Form
{
[DllImport("SWEnative.dll")]
static extern int ShowWinFormControl(IntPtr handle);
...
private void SilverlightClickEventHandler(StringBuilder msg)
{
// Create an instance of the winforms user control we want to
// plug into the Silverlight display
UserControl1 uc = new UserControl1();
uc.Visible = true;
// Tell the Silverlight UI about it and it will display it
ShowWinFormControl(uc.Handle);
}
}
http://www.WindowsEmbedded.com
http://msdn.microsoft.com/en-us/windowsembedded
http://social.msdn.microsoft.com/Forums/enUS/category/embeddedwindows/
http://social.msdn.microsoft.com/Forums/enUS/category/windowsembeddedcompact
https://connect.microsoft.com/windowsembeddedce
WEM201 | Discover Windows Embedded Standard 7 as Your Next Application Platform
WEM301 | Deploying Windows Embedded Standard 7 with Style
WEM302 | Explore the Multimedia Potential of Windows Embedded Standard 7
WEM303 | Gamechanger: Using Microsoft Silverlight for Windows Embedded to Create an Amazing Embedded UI
WEM305 | How to Choose a Windows Embedded Operating System
WEM306 | Using the Sensor & Location API on Windows Embedded Standard 7 to Create Exciting Connected Applications
WEM307 | Windows Embedded Compact: New Tools and Developer Story
WEM308 | Windows Embedded Overview: Demos of the Latest and Upcoming Releases
WEM309 | Programming Microsoft Silverlight for Windows Embedded Using Microsoft .NET
WEM01-INT | Build a Secure Device with Windows Embedded Standard 7
WEM02-INT | Delivering Flexible Peripheral Support for Point of Sale
WEM03-INT | How Windows Embedded Solutions Help to Protect the Environment
WEM05-INT | What a Desktop Developer Needs to Know to Develop for Windows Embedded
WEM06-INT | Windows Embedded Compact Compete
WEM07-INT | Server Appliances with Windows Embedded Servers
WEM08-INT | Roundtable: Windows Embedded @ Tech·Ed 2011 - Tell Us What You Want to Learn
WEM01-HOL | Build Your Own Embedded System
WEM04-HOL | Porting Third-Party Drivers into Image Configuration Editor
TLC-46 | Get Your Hands on Windows Embedded
TLC-47 | Powered by Windows Embedded POSReady – Touch Screen
TLC-48 | The Intel® Intelligent Digital Signage Proof of Concept
TLC-49 | Windows Embedded Automotive
TLC-50 | Windows Embedded Device Showcase
www.microsoft.com/teched
www.microsoft.com/learning
http://microsoft.com/technet
http://microsoft.com/msdn
Sign up for Tech·Ed 2011 and save $500
starting June 8 – June 31st
http://northamerica.msteched.com/registration
You can also register at the
North America 2011 kiosk located at registration
Join us in Atlanta next year