Advertisement

FloatableWindow source on CodePlex

I got enough feedback and suggestions that I figured it would be better just to put the code up on CodePlex rather than package zips on my blog :-).  Here it is: FloatableWindow project.  The latest build I have is up there which incorporates some feedback that I’ve received.

UPDATE: If you like this idea VOTE FOR IT in the Silverlight Toolkit!

Basically the ShowDialog() API operates the same way that ChildWindow.Show() does today.  No changes there, popup is used.  But when you just want some simple MDI type windows, use Show() which will not use Popup but rather add the elements as children to your root visual.  Now the key here is defining that root.  Before you show the window you’d want to do something like this:

   1: FloatableWindow fw = new FloatableWindow();
   2: fw.Width = 200;
   3: fw.Height = 200;
   4: fw.Title = "Foobar";
   5: fw.ParentLayoutRoot = this.LayoutRoot;
   6: fw.VerticalOffset = 200;
   7: fw.HorizontalOffset = 100;
   8: fw.Show();

Notice line #5 where I specify a Panel element to add it to?  That would be required.  An ArgumentNullException is thrown if it is not provided.

Thanks for the great feedback and encouragement on this refactoring.  I hope that putting it on CodePlex provides a better home for evolution and tracking issues (I know there is an animation issue now with non-modal).


This work is licensed under a Creative Commons Attribution By license.

  1. 7/21/2009 3:14 PM | # re: FloatableWindow source on CodePlex
    Thanks Tim, We all really appreciate this :)
  2. 7/21/2009 3:57 PM | # re: FloatableWindow source on CodePlex
    Nice one Tim. Might use that today.
  3. 7/21/2009 11:20 PM | # re: FloatableWindow source on CodePlex
    Hey Tim, been messing with your download files, thanks a lot for the source code!

    1 quick question... about the line number 5 fw.ParentLayoutRoot = this.LayoutRoot;

    The ParentLayoutRoot property doesn't appear to exist... any idea what I am doing wrong?
  4. 7/21/2009 11:23 PM | # re: FloatableWindow source on CodePlex
    Allow me to clarify that, the fw FloatingWindow Object does have a property listed as Parent, but it appears to behave different (or be a different type)
  5. 7/21/2009 11:47 PM | # re: FloatableWindow source on CodePlex
    hmmm well I still get get the Window that I initialize in the main page to show up (prolly cuz as I mentioned earlier, that ParentLayoutRoot property seemed to evade me for whatever reason...

    But, I did manage to use a button to generate windows like in your example!!! I am pumped man, thanks a million, you rock!

    I will continue to play with this and check back frquently
  6. 7/22/2009 4:44 AM | # re: FloatableWindow source on CodePlex
    Hi Tim, What benefits do CodePlex have? I want to find a good way to store and organize my works as well.
  7. 7/22/2009 8:43 AM | # re: FloatableWindow source on CodePlex
    Hi Terence - CodePlex is a place for hosting open source projects. It has full project integration and uses Team Foundation Server on the backend. It really isn't a place for managing samples, but one for more full-fledged projects/frameworks/components with an open source license and the goal of collaborating.

    There is the MSDN Code Gallery which is similar in nature where you can put code samples. http://code.msdn.microsoft.com
  8. 7/22/2009 9:11 AM | # re: FloatableWindow source on CodePlex
    Cain -- you bring up a good point on ParentLayoutRoot -- are you creating the window in XAML? I didn't make it a dependency property so it wouldn't show up there...but you are right that it should be. It should be visible in code though.
  9. 7/22/2009 9:21 AM | # re: FloatableWindow source on CodePlex
    Hi Tim,
    Thanks for sharing this code on CodePlex.

    Best regards,
    Chris
  10. 7/23/2009 1:04 AM | # re: FloatableWindow source on CodePlex
    Is is just me or the HorizontalOffset and VerticalOffset do not work anymore? I used the previous version and that worked just fine.
    P.S. Great job with the ParentLayoutRoot, really needed it.
  11. 7/23/2009 1:27 AM | # re: FloatableWindow source on CodePlex
    I used the 30044 version, forgot to mention. And by previous version I was referring to the one from the previous post.
  12. 7/23/2009 7:22 AM | # re: FloatableWindow source on CodePlex
    alex_b -- can you post your code? It should be working...will be offset based on ParentLayoutRoot though, not the screen.
  13. 7/24/2009 1:15 AM | # re: FloatableWindow source on CodePlex
    In my project, the ParentLayoutRoot is be the first grid inside a TabItem and even if I hardcode the offsets, it is still displayed in the same position (somewhere close to the top-left on the TabItem).
    I added a new Silverlight Application project to the project downloaded from codeplex, chose not to host it in a new website, and in the generated MainPage.xaml.cs constructor I put the exact code from your post (those 8 lines). When I run it, the FloatableWindow is always centered, no mather what offset I specify. I tried this on another machine with the same result.
  14. 7/25/2009 7:21 AM | # re: FloatableWindow source on CodePlex
    Hi Tim,
    FloatableWindow is awesome.I got a question but not related with FloatableWindow :)
    I have a datagrid and dataform in main form;dataform in childwindow.When i click add new button ,i popup a childwindow to add record;the question is how can i check childwindow's dataform has errors and if it has errors,cancel adding records
  15. 7/25/2009 9:00 PM | # re: FloatableWindow source on CodePlex
    Tim:
    This control is fantastic! It is changing the way i develop LOB apps.
    In some way, this is the kind of "dataform" I needed.
    Now i have to acomplish how to put datafields and async validation inside it, then i will be happy!! lol.
    Keep on going and thank you again!
    Horacio
  16. 7/28/2009 7:03 PM | # re: FloatableWindow source on CodePlex
    Just noticed something while I was trying to use this in conjunction with the navigator... when I tried to modify the ParentLayoutRoot programatically, it lets me set the ParentLayoutRoot do a new location, but then at compile time, it throws an error.

    I got around this with the following code:

    oldWin.ParentLayoutRoot.Children.Remove(oldWin);
    oldWin.ParentLayoutRoot = this.Playground;
    oldWin.Show();

    Just thought this maybe useful to someone else so I figured I would share it
  17. 7/30/2009 6:35 PM | # re: FloatableWindow source on CodePlex
    Awesome! Definitely going to be using this. BTW, maybe I'm using it wrong, but it doesn't seem to be playing the opening animation when using Show() instead of ShowDialog(). I'm guessing this is by design so that the overlay doesn't show up... I'll play with it later when I have time and see if I can change the template a bit if there's an issue.

    Thanks for posting this! I missed it the first time around.
  18. 7/30/2009 6:58 PM | # re: FloatableWindow source on CodePlex
    Steve -- nope you aren't mistaken...I haven't had a chance to work that out yet. See floatablewindow.codeplex.com/.../View.aspx
  19. 7/31/2009 4:40 AM | # re: FloatableWindow source on CodePlex
    Hi Tim,

    It is very nice. I have one more questions.

    can we restrict the draging the FlatableWindow in a Grid instead of dragging the whole silverlight control area.

    Thx
    Siva
  20. 7/31/2009 8:51 AM | # re: FloatableWindow source on CodePlex
    Sivarajan - I believe someone is working on submitting a patch to do just that.
  21. 8/12/2009 10:26 PM | # re: FloatableWindow source on CodePlex
    Hey Tim, wondering if there are any ready made styling templates for the Floatable Window? Just some sort of skin I can load on to change the appearance easily, something like that
  22. 8/12/2009 10:35 PM | # re: FloatableWindow source on CodePlex
    Cain -- no templates that I'm aware of...but it should be stylable -- most of the elements are template parts.
  23. 9/16/2009 2:43 PM | # re: FloatableWindow source on CodePlex
    It seems that the floating window is restricted to the first row in the layout root grid in my project. Am I doing something wrong, or is there a way to allow it to move/resize across multiple rows?
  24. 9/16/2009 2:44 PM | # re: FloatableWindow source on CodePlex
    David you need to set the ParentLayoutRoot element correctly
  25. 1/8/2010 11:07 AM | # re: FloatableWindow source on CodePlex
    Hi Tim,

    Is there a way to close the floating window from the "parent" application??

    The "Parent" is the "this.LayoutRoot"

    In this code segment...

    public MainPage()
    {
    InitializeComponent();

    floatableWindow = new FloatableWindow();

    floatableWindow.ParentLayoutRoot = this.LayoutRoot;
    floatableWindow.Title = "Loading the data...";
    floatableWindow.ResizeMode = ResizeMode.NoResize;
    Canvas.SetLeft(floatableWindow, (double)25);
    Canvas.SetTop(floatableWindow, (double)25);
    floatableWindow.Height = 200;
    floatableWindow.Width = 200;
    floatableWindow.VerticalOffset = 200;
    floatableWindow.HorizontalOffset = 100;

    floatableWindow.Show();


    floatableWindow.Close();

    }



    I receive an error....

    System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object." StackTrace: at System.Windows.Controls.FloatableWindow.Close() at KnowledgeBase.MainPage..ctor() at KnowledgeBase.App.Application_Startup(Object sender, StartupEventArgs e) at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) InnerException:


    But the object is there, and I can see the title in the floatover debugger


    thanks for your work on this!!


    take care
    tony
  26. 1/28/2010 12:39 PM | # re: FloatableWindow source on CodePlex
    Same problem :/

    Hi Tim: this control is just what I needed... But, It thows the following Exception once closed the control.

    Object reference not set to an instance of an object in System.Windows.Controls.FloatableWindow.<Close>b__0(Object s, EventArgs args)
    en System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
    in MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

    Im not trying to access any information on the Closed EventHandler neither.
    First I created a control by using the FloatableWindow template, And then i just created the Window on CodeBehind. But stills the same issue...

    Im running v3.0.40624.4 Release of the dll on SL v3.0.50106.0 in a C# project w/RiaServices

    Thanks
  27. 2/2/2010 8:41 AM | # re: FloatableWindow source on CodePlex
    Tony , you have to set the ParentLayoutRoot Property
    Ex
    floatableWindow.ParentLayoutRoot = this.LayoutRoot;

 
Please add 7 and 4 and type the answer here:
First time here? You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting! (hide this)