Hi, I have a WPF xaml file and I''d like to execute it using IronRuby. I know I can use the System::Windows::Markup::XamlReader.parse method, but is there another way? Using the XamlReader class makes registering events, for example, kind of an irritating task. Thanks, Shay. -- Posted via http://www.ruby-forum.com/.
Shay Friedman wrote:> Hi, > > I have a WPF xaml file and I''d like to execute it using IronRuby. I know > I can use the System::Windows::Markup::XamlReader.parse method, but is > there another way? > > Using the XamlReader class makes registering events, for example, kind > of an irritating task. > > Thanks, > Shay.Yes, there is a ''Wpf.rb'' in your \Samples\Tutorial directory (This should exist for you if you have a source copy, or the regular 0.6 release) This adds a number of helpers to make working with XAML easier. I haven''t looked at it extensively, but I''d say you can probably learn what is doing by running the wpf tutorial in that dir, and following the source. Look for the "load" methods associated with xaml to get an idea of what helpers are added. Also, if you are trying to do something simple, and the XAML is actually getting in the way, Thibaut Barr?re''s "magic" looks to be a very nice DSL for this: http://github.com/thbar/magic/tree/master -- Posted via http://www.ruby-forum.com/.
I was looking through the mailing list archives for unanswered mails ... eek, sorry Shay! Well, if you still have this question ... You can also load XAML with System::Window::Application.LoadComponent: # This loads "foo.xaml" into the "canvas" variable include System include System::Windows include System::Windows::Controls canvas = Canvas.new Application.load_component canvas, Uri.new("foo.xaml", UriKind.relative) This only works when foo.xaml has a x:Class equal to the type passed to the first arg to load_component, like x:Class="System.Windows.Controls.Canvas". ~Jimmy> -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core- > bounces at rubyforge.org] On Behalf Of Shay Friedman > Sent: Friday, July 24, 2009 2:34 AM > To: ironruby-core at rubyforge.org > Subject: [Ironruby-core] How to run a XAML file? > > Hi, > > I have a WPF xaml file and I''d like to execute it using IronRuby. I know I > can use the System::Windows::Markup::XamlReader.parse method, but is there > another way? > > Using the XamlReader class makes registering events, for example, kind of an > irritating task. > > Thanks, > Shay. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core
Thanks Jimmy :) On Mon, Nov 16, 2009 at 5:32 AM, Jimmy Schementi < Jimmy.Schementi at microsoft.com> wrote:> I was looking through the mailing list archives for unanswered mails ... > eek, sorry Shay! Well, if you still have this question ... > > You can also load XAML with System::Window::Application.LoadComponent: > > # This loads "foo.xaml" into the "canvas" variable > include System > include System::Windows > include System::Windows::Controls > canvas = Canvas.new > Application.load_component canvas, Uri.new("foo.xaml", UriKind.relative) > > This only works when foo.xaml has a x:Class equal to the type passed to the > first arg to load_component, like x:Class="System.Windows.Controls.Canvas". > > ~Jimmy > > > -----Original Message----- > > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core- > > bounces at rubyforge.org] On Behalf Of Shay Friedman > > Sent: Friday, July 24, 2009 2:34 AM > > To: ironruby-core at rubyforge.org > > Subject: [Ironruby-core] How to run a XAML file? > > > > Hi, > > > > I have a WPF xaml file and I''d like to execute it using IronRuby. I know > I > > can use the System::Windows::Markup::XamlReader.parse method, but is > there > > another way? > > > > Using the XamlReader class makes registering events, for example, kind of > an > > irritating task. > > > > Thanks, > > Shay. > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Ironruby-core mailing list > > Ironruby-core at rubyforge.org > > http://rubyforge.org/mailman/listinfo/ironruby-core > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-- -------------------------------------------------- Shay Friedman Author of IronRuby Unleashed http://www.IronShay.com Follow me: http://twitter.com/ironshay -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091116/4c8cfbfa/attachment.html>
> -----Original Message----- > From: ironruby-core-bounces at rubyforge.org > Jimmy Schementi > Sent: Monday, November 16, 2009 5:32 AM > > # This loads "foo.xaml" into the "canvas" variable include > System include System::Windows include > System::Windows::Controls canvas = Canvas.new > Application.load_component canvas, Uri.new("foo.xaml", > UriKind.relative)I was looking for ways to load XAML to a custom class from a file at runtime in the way described above. I have load_component.rb: require ''PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'' require ''PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'' require ''WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'' include System include System::Windows include System::Windows::Controls canvas = Canvas.new Application.load_component(canvas, Uri.new("foo.xaml", UriKind.relative) ) I have my foo.xaml file in the same location as the ruby script above. When I run the script with "ir load_component.rb" I get error: PresentationFramework:0:in `GetStreamCore'': Cannot locate resource ''foo.xaml''. (IOError) from WindowsBase:0:in `GetStream'' from WindowsBase:0:in `GetStream'' from PresentationFramework:0:in `LoadComponent'' from loadcomponent.rb:0 Where should I put the foo.xaml for the script above to find it? Only examples I found from Application.LoadComponent from MSDN were using relative URI:s referring to XAML-files embedded in some assembly. I want to load a XAML-file on a disk however. XamlReader.Load is not enough for me since I need to have custom classes created with the xaml:class="..." attribute. Robert Brotherus