Accessing XAML from IronRuby
With the Windows namespace imported, you can access the XAML code in the application using the Silverlight Application namespace. This is done by using the Application.current. load_root_visual() function.
The load_root_visual() function accepts two arguments. The first is a DependencyObject of the same type as the root element in the XAML. The second argument is a string specifying the location of the XAML file relative to the currently executing code.
For example, the following line of code retrieves the root element of the XAML file named app.xaml with a UserControl as the root element:
@xaml = Application.current.load_root_visual(UserControl. new,"app.xaml")
The code uses the UserControl.new constructor to build the DependencyObject.
Using the root element of the XAML, you can access other objects in the XAML file. Consider the code in Listing 11.6 that specifies a TextBlock control named titleBlock. You can modify the Text attribute of titleBlock using the following line of Ruby code:
@xaml.titleBlock.Text = 'Welcome to IronRuby'
Average user rating: 5 stars out of 2 votes
Post a comment