logo WinWrap®

WPF XAML Hello World!

WinWrap® Basic is an embedded language control available for .NET/COM 32/64 bit Windows applications. The WinWrap® Basic Component is compatible with VBA, Sax Basic, VB.NET and Visual Basic 6.0 style scripts.

Display custom WPF XAML UI Dialogs from WinWrap® Basic scripts. Incorporate any WPF control. Show custom user interfaces for specific clients.

Use Custom WPF XAML UI Forms with your WinWrap® Basic Application

  • Utilize any Windows Presentation Foundation (WPF) UI Control
  • Works with .NET, WPF, and COM applications
  • Dynamically display custom WPF UI from XAML description code
  • Implement custom user interfaces for specific clients
  • Enable power users to implement their own custom interfaces
  • Access host application specific extensions
  • Requires WinWrap® Basic with WWB-NET scripting option

WPF XAML Project Example

WinWrap® Basic WPF XAML HelloWorld! Example

The XAML definition specifies the "Hello World" dialog UI controls and layout.
  • Divide the dialog window into menu and regular areas
  • Define top menu and menuitem mnuExit
  • Define textbox txtBox1
  • Define button btnHello
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF XAML Dialog" Height="350" Width="525"> <Grid Name="grid1" ShowGridLines="False"> <Grid.RowDefinitions> <RowDefinition Height="23" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Menu Grid.Row="0" HorizontalAlignment="Stretch"> <MenuItem Header="_File"> <MenuItem x:Name="mnuExit" Header="Exit" /> </MenuItem> </Menu> <TextBox Name="txtBox1" Grid.Row="1" Text="World" Height="23" HorizontalAlignment="Left" Margin="135,80,0,0" VerticalAlignment="Top" Width="120" /> <Button Name="btnHello" Grid.Row="1" Content="Hello" Height="23" HorizontalAlignment="Left" Margin="135,112,0,0" VerticalAlignment="Top" Width="120" /> </Grid> </Window>
The clsHelloDialog Class script is the code representation of the XAML UI dialog
  • Define the dialog window and .NET framework controls
  • Read and instantiate the WPF window
  • Show the XAML Dialog
  • Bind the .NET framework controls to the instantiated XAML dialog elements
  • Sink the "Hello Button" click event
  • Sink the "Exit MenuItem" click event
Public Class clsHelloDialog ' Define the dialog window and .NET framework controls Dim WithEvents wndMain As Windows.Window Dim WithEvents mnuExit As Windows.Controls.MenuItem Dim WithEvents txtBox1 As Windows.Controls.TextBox Dim WithEvents btnHello As Windows.Controls.Button ' Read and instantiate the XAML window Public Sub Show() Using reader As New Xml.XmlTextReader(MacroDir & "MyProject-xmlHelloDialog.xaml") wndMain = Windows.Markup.XamlReader.Load(reader) End Using ' Bind the .NET framework controls to the instantiated XAML dialog elements mnuExit = wndMain.FindName("mnuExit") txtBox1 = wndMain.FindName("txtBox1") btnHello = wndMain.FindName("btnHello") 'ShowModeless() ShowModal() End Sub ' Show the XAML Dialog (modeless - can be debugged in WinWrap Basic) Public Sub ShowModeless() System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(wndMain) wndMain.Show While wndMain.IsVisible Wait .1 End While End Sub ' Show the XAML Dialog (modal - can't be debugged in WinWrap Basic) Public Sub ShowModal() wndMain.ShowDialog End Sub ' Sink the "Hello Button" click event Private Sub btnHello_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) _ Handles btnHello.Click MsgBox(btnHello.Content & " " & txtBox1.Text & "!") End Sub ' Sink the "Exit MenuItem" click event Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) _ Handles mnuExit.Click wndMain.Close() End Sub End Class
Create the dialog object and then call its Show method.
  • Create the clsHelloDialog object
  • Call the dialog object Show method
  • Load and control the WPF window
Public Module modMain ' Create the clsHelloDialog object Dim dlgHello As New clsHelloDialog Sub Main ' Call the dialog object Show method ' Load and control the WPF window dlgHello.Show() End Sub End Module
The "EntryPoint Main" command selects the "Sub Main()" subroutine to begin executing.
'#Language "WWB.NET" Imports System Project Project1 Optimizer Off EntryPoint Main LoadModule "MyProject-modMain.wwm" LoadModule "MyProject-clsHelloDialog.wwm" End Project
You can download prjWPF-HelloWorld.zip clicking the following link: WinWrap® Basic WPF XAML HelloWorld! example. Then open the Project1.wwp project with WinWrap® Director. WinWrap® Director is part of the WinWrap® Basic Scripting evaluation product.

Copyright Polar Engineering, Inc.