[Mono-list] Scope of MainWindow methods & Stetic created widg ets

Ian Norton ian.norton-badrul at thales-esecurity.com
Fri Aug 5 02:59:59 EDT 2011


On Thu, Aug 04, 2011 at 03:23:44PM +0100, jimevt wrote:
> Hello Again,
>    Well, passing the MainWindow into the RTDFile constructor does work,
> though it doesn't seem like the correct way to do things.
> 
>    Callbacks - I was thinking of signal handlers, which aren't the same
> thing at all.   Can you refer me to documentation on creating a call back?

Um, well, I'd do it like this if I wanted to just pass the status bar:

// RTDFile.cs

public partial class RTDFile {
  public StatusBar Status { get; set; }

  void SomeMethod()
  {
    Status.Push(0, String.Format("Downloading {0}", filename));
  }

}

// MainWindow.cs

public partial class MainWindow : Window {

  public MainWindow() {
    this.Build();

    this.File = new RTDFile();
    this.File.Status = this.Statusbar1;
  }
}

Or this if I wanted to use a delegate

// RTDFile.cs

public partial class RTDFile {
  public Action<uint,string> SetStatus { get; set; }

  void UpdateStatus( params string[] message ) {
    if ( SetStatus != null ){
      SetStatus( 0, String.Format( message ) );
    }
  }
  
  void SomeMethod() {
    SetStatus("Downloading {0}", filename);
  }
}

// MainWindow.cs

public partial class MainWindow : Window {

  public MainWindow() {
    this.Build();
    this.File = new RTDFile();
    this.File.SetStatus = SetStatus;
  }

  public void SetStatus( uint id, string message ) {
    this.Statusbar1.Push( id, message );
  }
}

Have Fun :)

Ian

>    Thanks!
> 
> JimE.
> 
> 
> --
> View this message in context: http://mono.1490590.n4.nabble.com/Scope-of-MainWindow-methods-Stetic-created-widgets-tp3717101p3718845.html
> Sent from the Mono - General mailing list archive at Nabble.com.
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list


More information about the Mono-list mailing list