Robert Brotherus
2009-Sep-04 07:45 UTC
[Ironruby-core] Getting initialize called for already-constructed dotnet-classes
I have a simple XAML that is compiled to Napa.Gui.MotifSupport.SpinBoxWidget CLR class: <UserControl x:Class="Napa.Gui.MotifSupport.SpinBoxWidget" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:m="clr-namespace:Napa.Gui.MotifSupport" Height="Auto" MinWidth="60"> <Grid> <Grid.RowDefinitions> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <m:InputField x:Name="Value"/> <ScrollBar x:Name="Scroll" Orientation="Vertical" Grid.Column="1"/> </Grid> </UserControl> At IR-side, I monket-patch initialize-methods for SpinBoxWidget and one of its parts: include Napa::Gui::MotifSupport def test_initialize SpinBoxWidget.class_eval do def initialize puts "SpinBoxWidget.initialize" end end InputField.class_eval do def initialize puts "InputField.initialize" end end puts ''Creating InputField'' InputField.new # Prints "InputField.initialize" puts "Creating SpinBoxWidget" s = SpinBoxWidget.new # Prints "SpinBoxWidget.initialize" but *not* "InputField.initialize" end So the InputField initialize is not executed when the InputField is created as part of the larger XAML. This is understandable, but still problem for us. Trying to call InputFields initialize afterwards fails as well with "initialize is private method" error. Our current solution is to use non-standard name "initializer" and manually execute that for all widgets and sub-widgets after construction. This does not feel very nice solution. Any other ideas out there? Robert Brotherus Napa Inc.