Advertisement
Anaristos

Lua WPF sample

Mar 31st, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. require("CLRPackage")
  2. --
  3. import("PresentationFramework")
  4. import("PresentationBase")
  5. import("PresentationCore")
  6. import("System.Windows")
  7. import("System.Windows.Controls")
  8. import("System.Windows.Markup")
  9. import("System.Windows.Media")
  10. import("System.Reflection")
  11. import("System.Xml")
  12. import("System.IO")
  13. --
  14. dynxaml11 = {}
  15. --
  16. function dynxaml11.ctor()
  17.  
  18.     local this = Window()
  19.  
  20.     local button, rd
  21.  
  22.     local xaml = [[
  23.                     <Page
  24.                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  25.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  26.                     <Page.Resources>
  27.                             <ResourceDictionary>
  28.                                 <ResourceDictionary.MergedDictionaries>
  29.                                     <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  30.                                                         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  31.                                         <SolidColorBrush x:Key="brush" Color="Red" />
  32.                                 </ResourceDictionary>
  33.                             </ResourceDictionary.MergedDictionaries>
  34.                         </ResourceDictionary>
  35.                     </Page.Resources>
  36.                     <Button x:Name="button" Content="Click Me" Height="100" Width="100"
  37.                             Background="{DynamicResource brush}"  />
  38.                     </Page>
  39.                  ]]
  40.  
  41.     local function button_Click( sender, e )
  42.  
  43.              
  44.  
  45.           end
  46.  
  47.     local function LoadXAML()
  48.  
  49. --            local fn = [[C:\Tony Gomez\Wlua\WpfTests\rd1.xaml]]
  50.  
  51. --            local fs = FileStream( fn, FileMode.Open )
  52.  
  53. --            rd = XamlReader.Load( fs )
  54.  
  55. --            this.Resources = rd
  56.              
  57.               this.Resources.Source = Uri( [[C:\Tony Gomez\Wlua\WpfTests\rd1.xaml]] )
  58.  
  59.               local mysr      = StringReader( xaml )
  60.               local xmlReader = XmlTextReader( mysr )            
  61.               local content   = XamlReader.Load( xmlReader )
  62.  
  63.               button = LogicalTreeHelper.FindLogicalNode( content, "button" )            
  64.  
  65.               return content
  66.  
  67.           end
  68.  
  69.     local function InitializeComponent()
  70.  
  71.               this.Width                 = 300
  72.               this.Height                = 175
  73.               this.Title                 = "Resource Test"
  74.               this.WindowStartupLocation = WindowStartupLocation.CenterScreen
  75.               this.Topmost               = true
  76.  
  77.               this.Content = LoadXAML()      
  78.  
  79.               button.Click:Add( button_Click )
  80.  
  81.           end
  82.    
  83.     InitializeComponent()
  84.    
  85.     return this
  86.    
  87. end
  88. --
  89. setmetatable( dynxaml11, { __call = function( _, ... ) return dynxaml11.ctor( ... ) end } )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement