Click here to Skip to main content
Click here to Skip to main content

FloatingWindow - Multi-windows Interface for Silverlight 4

By , 16 May 2011
 

Before you start reading - click on the FloatingWindow demo link to see whether it can be interesting for you. If yes - take it here:

If your browser understands Silverlight 4, you will see something like this:

FloatingWindow demo

Windows in 21 Days

Indeed it required a bit more time to write this library. Though floating windows are common in graphics applications, there are not too many such controls in Silverlight. One of the best is Tim Heuer's FloatableWindow control.

Starting this project, I just wanted to add a few functions to the existing control. But it turned out it was easier to rewrite it completely. Finally, only a few original methods had left after my rework. I added the following functionality:

  • Window can be resized by dragging any edge or a corner
  • Added possibility to snap in moving or resizing window to the nearest window's boundary
  • Window can be minimized, maximized and restore its position and size
  • Window can be opened in modal mode
  • Window can save and restore its size and position
  • Added an icon bar, displaying minimized or all windows
  • The icon bar can display a snapshot of a minimized window or an icon - a FrameworkElement attached to the window.

What's Inside

It would take too much time to explain how it works in details. I am sure, you (like me) don't like reading long boring documents. After all, you have my source code. I'd better describe how it can be used. But before we start, I'll introduce some terms and properties used in the library. The picture below will help me to illustrate them.

FloatingWindow Properties

Where the most important elements are:

  • FloatingWindow - Base class of the resizable windows
  • FloatingWindowHost - Canvas element containing floating windows
  • Iconbar - Panel containing icons of the minimized windows
  • Bootstrap Button - Button opening the Iconbar

Classes and their Members

This section contains a list of the most useful class members.

FloatingWindow Class

  • DialogResult - A value that indicates whether the FloatingWindow was accepted or canceled
  • FlowDirection - The direction that title text flows within window's icon
  • Icon - Content displayed as an icon of the window on the iconbar. If not specified - a snapshot of the window will be displayed as an icon
  • IconText - Text displayed on the icon of the minimized window
  • Position - Current window position
  • ResizeEnabled - A value indicating whether resizing is enabled
  • ResizingAreaThickness - The width of the resizing area
  • ShowInIconbar - A value indicating whether to show minimized window in the iconbar
  • ShowCloseButton - A value indicating whether to show Close button
  • ShowMaximizeButton - A value indicating whether to show Maximize button
  • ShowMinimizeButton - A value indicating whether to show Minimize button
  • Title - Content displayed on the top of the window. Can contain any UI elements
  • TitleBackground - The title background
  • Close - Closes a window
  • RestoreSizeAndPosition - Restores window size and position stored in the IsolatedStorage at the close of the window
  • RestoreWindow - Restores window state, size and its position if it was minimized or maximized
  • Show - Shows a window
  • ShowModal - Shows a window in modal mode
  • Activated - Window is activated and got focus
  • Closed - Window is closed
  • Closing - Window is closing
  • Deactivated - Window is deactivated
  • Maximized - Window is maximized
  • Minimized - Window is minimized
  • Restored - Window is restored

FloatingWindowHost Class

  • IconWidth - The width of the window's icon
  • IconHeight - The height of the window's icon
  • OverlayBrush - The overlay color
  • SnapinEnabled - A value indicating whether snap in is enabled
  • SnapinDistance - Distance between two windows' boundaries when moving window is "attracting" to another one
  • SnapinMargin - A gap between two adjacent windows
  • ShowMinimizedOnlyInIconbar - A value indicating whether to show only minimized windows in the iconbar
  • WindowIconWidth - The width of the iconbar item
  • WindowIconHeight - The height of the iconbar item
  • CloseAllWindows - Closes all floating windows
  • HideIconbar - Hides the iconbar
  • ShowIconbar - Shows the iconbar

Other properties can be found in the code.

Getting Started

The windows are "floating" in the FloatingWindowHost - a Canvas control, which shall be created first, for example, in the markup:

<my:FloatingWindowHost x:Name="host" 
    SnapinEnabled="True" ShowMinimizedOnlyInIconbar="False">
</my:FloatingWindowHost>

The next step - we shall add our windows to the host:

FloatingWindow window = new FloatingWindow();
window.Title = "New window";
host.Add(window);
window.Show();

Created window is hidden. The FloatingWindow class has three overloaded methods Show(). The first overload takes no parameters and displays the window in the center of the hosting container. The second and third overloads show the window in the specified coordinates.

There is another option: to restore window size and position saved when the window was closed. Don't worry about saving these parameters. They will be automatically stored in the IsolatedStorage at the close of the window if you specify a unique window's Tag. You can set it during runtime or in the XAML:

<my:FloatingWindow x:Class="FloatingWindowControl.DetailsForm"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:my="clr-namespace:SilverFlow.Controls;assembly=SilverFlow.Controls"
    Height="Auto" MinWidth="100" MinHeight="100"
    Title="Details" IconText="Details Form" Tag="Details">

Now you can call the RestoreSizeAndPosition() method to show the window in the previously saved coordinates:

detailsForm.RestoreSizeAndPosition();
detailsForm.Show(); 

In version 1.2, new ShowModal() method was added to display a floating window in modal mode. It blocks access to underlying windows displaying an overlay above them. The color of the overlay is defined by the OverlayBrush property.

Modal window

Like the ChildWindow it has a DialogResult property, which can be retrieved on windows closing:

FloatingWindow window = new FloatingWindow(); 
window.Title = "Confirmation"; 
host.Add(window); 
window.ShowModal(); 
window.Closed += (s, a) =>
    {
        bool? result = window.DialogResult;
    };  

The major distinction between the modal window and the ChildWindow is that the last one blocks access to the whole area occupied by the Silverlight application, while the floating window in modal mode - only parent FloatingWindowHost.

If you need to know which window becomes active (gets focus), you can subscribe to the Activated or Deactivated events added in the version 1.2.1 (see the MainPage.xaml.cs):

FloatingWindow window = new FloatingWindow();
host.Add(window);
window.Activated += (s, a) =>
    {
        Debug.WriteLine("Activated: {0}", window.IconText);
    };

Now windows are displayed and we can switch between them, move and resize. Selected window becomes topmost and gets focus. If we want a window to be displayed always above others, we can set its TopMost property to true.

Appearance of the window is defined in the generic.xaml file.

Honey, I Shrunk the Windows

When we move or resize a window, it sticks to the nearest boundaries. Maximal distance at which the window attracts to other windows is 5 pixels and is defined in the SnapinDistance property. If you don't like the windows sticking close to each other, you can specify non-zero SnapinMargin - a gap between adjacent windows. "Mind The Gap" as they say in London.

We can enable or disable resizing setting ResizeEnabled property. Besides, it is possible to disable resizing by one of the coordinates. For example, if we set window's MinWidth equals to its MaxWidth, the window can't be resized by the X coordinate.

Writing code for resizing, I created two interesting (at least for me) by-products: ResizeController and SnapinController. They are more or less independent from other parts of the code and I am going to use them in my other controls.

Dude, Where is my Window?

If we provide a possibility to minimize windows, we shall give quick access to them. And not only to minimized ones because some windows can be moved out of the visible area of the windows container. That's why I recommend to set ShowMinimizedOnlyInIconbar property to false.

The icon bar emerges each time when we press the bootstrap button at the bottom of the windows container and hides when we click on an icon. It contains windows' thumbnails ordered by the IconText. If you don't want to display a window's icon on the icon bar, set its property ShowInIconbar to false.

Window's thumbnail is displayed as a snapshot of the window if the Icon property is not set. Otherwise, the FrameworkElement set by the property will be displayed. For example, look at the markup of the WindowWithChart.xaml:

<my:FloatingWindow.Icon>
    <my1:MyIcon />
</my:FloatingWindow.Icon>

It defines the MyIcon UserControl as an icon of the window. Nice looking, isn't it? If you want to use an image as an icon, you shall specify its dimensions:

<my:FloatingWindow.Icon>
    <Image Source="Images/computer.png" Width="48" Height="48"></Image>
</my:FloatingWindow.Icon>

How to Add It to your Project

Here you have a short step-by-step instruction:

  1. Find the FloatingWindowTemplate.zip in the downloaded archive and copy the ZIP file to the ItemTemplates folder of your Visual Studio. On my machine, it is the "C:\Users\Eugene\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#" folder.
  2. Add the SilverFlow.Controls.dll as a reference to your Silverlight project.
  3. Copy the resource dictionary generic.xaml from the SilverFlow.Controls project to your Silverlight project and add it to your application resources.
  4. Right-click on your Silverlight project, select "Add > New Item...", and select the FloatingWindow Control item template.
  5. Build the project.
  6. Add the FloatingWindowHost control to your page, hosting the "floating" windows. See the MainPage.xaml how to do that.
  7. Add a code, creating and displaying the "floating" windows.

Afterword

First, I would like to thank you all for your contribution, ideas, notes and critique. I do not promise to answer all your letters or implement all your proposals. After all, you are free to use and modify this code.

From time to time, I publish new versions of the FloatingWindow control on my site jevgenijpankov.heliocode.com.

If you create something interesting using this library, please write to me, and I'll publish links to your most impressive examples.

References

History

  • 24th October, 2010 - Initial version
  • 12th February, 2011 - Version 1.2
    • Fixed a few bugs
    • Reworked the Iconbar
    • Added modal mode
  • 12th May, 2011 - Version 1.2.1
    • Fixed some bugs
    • Added Activated and Deactivated events
    • Added RestoreSizeAndPosition method

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jevgenij Pankov
Latvia Latvia
Member
Jevgenij lives in Riga, Latvia. He started his programmer's career in 1983 developing software for radio equipment CAD systems. Created computer graphics for TV. Developed Internet credit card processing systems for banks.
Now he is System Analyst in Accenture.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionNice!membervk00028 Mar '13 - 11:05 
Very nice. I will try using it in our project(s).
QuestionHow to open a new floatingwindow in the host from a floatingwindowmemberJaggernaut29 Jan '13 - 0:16 
Hi there, is there a way to open a new floating window in the floatingwindow host using let's say a button in another floating window?
Wexelblats algorithm:
Pick two: 1. Good, 2. Fast, 3. Cheap

QuestionFonts problemmemberdtcDev17 Jan '13 - 20:24 
Hi.
Great work, thanks. Its realy nessesary controls toolkit. But i have some font problem. He is not clear, near letters i see grayscale effects. Looks like not ended scale transform effect.
 
How can i fix this?
QuestionOne Smaill Question?membernhbcyz16 Jan '13 - 21:52 
So Thank for supply the contorls.
I found the floating window has disappeared when I drag it toward bottom or right,I can't control the floatingwindow's boundary when i was moving it.

I want the floating window just display in the floatingwindowhost.
Please help me!
QuestionRe: Scroll BarmemberYazid2 Jan '13 - 11:44 
Excellent article, is it possible to have a scroll bar on the host, so that I scroll horizontally or vertically to see more windows?
Questionfloatingwindow and vs 2012 wpf designer bugmembermolana79 Oct '12 - 9:35 
floatingwindow and vs 2012 wpf designer bug
GeneralMy vote of 5memberThad Tilton9 Oct '12 - 8:12 
Awesome and useful ... very well written.
QuestionBootstrp Button not workingmemberSantoshf223 Aug '12 - 2:56 
Hi,
First I loved your work, helped me a great deal in few of my projects, but I do have a problem with the bootstrap, when I popup a window and click on bootstrap it throws an error saying "Template Part PART_Title is required to display WindowIcon."
the thumbnail image is empty..
How do I fix this
Please guide me...
AnswerRe: Bootstrp Button not workingmemberJevgenij Pankov23 Aug '12 - 18:52 
Hi,
 
That means your Control Template for the WindowIcon does not contain a text block:
 
GeneralRe: Bootstrp Button not workingmemberSantoshf223 Aug '12 - 19:11 
Hi, Thank you for replying
I attached the dll , added the FloatingWindow to the project and called it to the FloatingWindowHost in the MainPage..
When I run it works perfectly except the boothstrap button..
Am I missing something here
 
Please guide...
GeneralRe: Bootstrp Button not workingmemberLuke Waldron19 Mar '13 - 3:50 
Hi Santoshf2, I am having the same problem. Did you find a solution to it? Thanks in advance.
QuestionIs your site down? [modified]memberJaggernaut25 Jun '12 - 1:18 
Hi there, I found this extremely interesting and visited your site last week and downloaded the project and have played around a bit with it. It has real potential. Smile | :)
 
However, my SSD went dead yesterday and today when I checked out the project from TFS I noticed that I was missing the DLL which I compiled from your code, and low and behold, the heliocode site is gone. Is this some temporary issue or is it in fact gone forever?
Wexelblats algorithm:
Pick two: 1. Good, 2. Fast, 3. Cheap


modified 25 Jun '12 - 9:01.

AnswerRe: Is your site down?memberJevgenij Pankov25 Jun '12 - 4:19 
Hi,
In fact, my hosting company migrated domains to new IPs. It seems it is working now.
 
Regards,
 
Jevgenij
GeneralRe: Is your site down?memberJaggernaut25 Jun '12 - 6:54 
Thank you very much, my evening is saved, I can continue my exploration into WPF. Smile | :)
It works again, like a charm. Big Grin | :-D
Wexelblats algorithm:
Pick two: 1. Good, 2. Fast, 3. Cheap

QuestionHow to know if the current window is maximized?memberdharmbhav9 Jun '12 - 14:11 
I want to know if the current window is maximized. I could not find any method/property for this...
Thanks in advance
dharmbhav

QuestionOpen modal or floating window from a floating windowmemberskwerlzU16 Apr '12 - 11:56 
When Itry to open another floatin window from an openedfloating window it doesn't seem to find the host. Any thoughts or ideas? I'm kind of a newbie.
BugProblem in Microsoft Expression Blend [modified]membermehdi550u7 Apr '12 - 19:45 
Hi.
This control do not show in Microsoft Expression Blend!!!!why?

modified 10 Apr '12 - 2:14.

QuestionPositionChanged?membermiketgates7 Apr '12 - 10:39 
Is there an event to hook into when the position of a window changes?
QuestionMap Componentmemberonurbasal5 Apr '12 - 12:42 
I realy love your component. It works just perfect. But I'm making GIS applications.So i always have to have a map on the screen.But with your component, I just can show floating windows on floating window host,and dominate my map. Is there any way to add my map or any other components inside of floating window host. If you answer me I would be appreciated.Thanks...
 
Onur
SuggestionRe: Map ComponentmemberSamuli Neuvonen7 Jun '12 - 20:50 
I solved this by adding a boolean attribute isBackgroundWindow into FloatingWindow and then checking for this value in FloatingWindowHost's OnActiveWindowChanged-method. If the window is set to be a background window, I skip all the code here and the window will never be brought to the top. Then I use this type of window for the map. May be a hack but seems to work. At least so far...
Samuli

GeneralRe: Map Componentmembermiri.eshel7 Jul '12 - 23:17 
Hi Samuli,
 
Thank you for sharing. Can you send a piece of code that demonstrates your changes. I also encountered the same problem.
 
Thanks a lot,
Miri
GeneralRe: Map ComponentmemberSamuli Neuvonen27 Sep '12 - 23:09 
Hello,
 
And sorry for the very VERY late reply, no excuses.
 
Let's see if I remember...
 
1. I added the following code to FloatingWindow.cs
 
       
 
#region public bool isBackgroundWindow
 
        /// <summary>
        /// Gets or sets a value indicating whether window is a "background".
        /// </summary>
        /// <value><c>true</c> if to set the window in background; otherwise, <c>false</c>.</value>
        public bool isBackgroundWindow
        {
            get { return (bool)GetValue(isBackgroundWindowProperty); }
            set
            {
                SetValue(isBackgroundWindowProperty, value);
                if(value == true)
                    this.MaximizeWindow();
            }
        }
 
        /// <summary>
        /// Identifies the <see cref="FloatingWindow.isBackgroundWindow" /> dependency property.
        /// </summary>
        /// <value>
        /// The identifier for the <see cref="FloatingWindow.isBackgroundWindow" /> dependency property.
        /// </value>
        public static readonly DependencyProperty isBackgroundWindowProperty =
            DependencyProperty.Register(
            "isBackgroundWindow",
            typeof(bool),
            typeof(FloatingWindow),
            new PropertyMetadata(false, isBackgroundWindowPropertyChanged));
 
        /// <summary>
        /// isBackgroundWindowProperty PropertyChangedCallback call back static function.
        /// </summary>
        /// <param name="d">FloatingWindow object whose isBackgroundWindow property is changed.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs which contains the old and new values.</param>
        private static void isBackgroundWindowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //FloatingWindow window = (FloatingWindow)d;
            //bool visible = window.IsModal ? false : (bool)e.NewValue;

            //if (window.restoreButton != null)
            //    window.restoreButton.SetVisible(visible);
        }
 
        #endregion
 
2. I added this
 
public void Activate()
{
     if(this.isBackgroundWindow!=true)
          SetTopmost();
}
 
and this
 
        protected virtual void OnActivated(EventArgs e)
        {
            if (this.isBackgroundWindow)
            {
                return;
            }
            else
            {
                EventHandler handler = Activated;
                if (handler != null)
                {
                    handler(this, e);
                }
            }
        }
 
3. Then, in FloatingWindowHost.cs, I added the following in to the beginning of the function SetTopMostWindow:
 
 
            if (window.isBackgroundWindow)
                return;
 
 
4. And the event handler OnActiveWindowChanged I changed into
 
protected virtual void OnActiveWindowChanged(ActiveWindowChangedEventArgs e)
        {
          
  if (e.Old!=null && e.Old.isBackgroundWindow)
            {
                return;
            }
            else
            {
                EventHandler<ActiveWindowChangedEventArgs> handler = ActiveWindowChanged;
 
                if (handler != null)
                    handler(this, e);
            }
        }
 
 
And that might be it. There could be something else, but I don't remember and I'm sure you'll figure it out by trying it out.
 
Hope that helped somebody somewhere.
GeneralRe: Map Componentmemberjenga30 Oct '12 - 13:41 
How did you define your FloatingWindowHost and your map component together? When I put the FloatingWindowHost together with my map control (ESRI Silverlight API), I no longer can interact/draw/identify on the map. Curious as to how you accomplished this...
GeneralRe: Map ComponentmemberSamuli Neuvonen11 Nov '12 - 20:42 
Hello,
 
I'm not sure if I understand you correctly, but your problem sounds to me like the original reason for extending the FloatingWindow with the property IsBackgroundWindow (explained earlier).
 
You can't put the map behind or inside the FloatingWindowHost, because then you can't interact with it. But when you put the map in one of the FloatingWindows, it works. So, the solution - for me at least - is to create the type of FloatingWindow that fills the whole FloatingWindowHost, has no top bar and never moves to foreground. All the other FloatingWindows of the host stay on top of the map.
 
However, I have to repeat I'm not sure I've mentioned every detail I changed/added. There could be something else that I just don't remember. Let me know If you don't get it to work.
 
Hope this helps,
SN
Questionmy Rate is 10 from 5memberiliahueck13 Mar '12 - 3:21 
im from iran. so 'damet garm' means thanks a lot Smile | :)
Questionrepublishe codememberRamesh.Addagatla8 Mar '12 - 20:53 
Hello Sir,
 
Thanks to publish such nice application, i like the app. and i decided to implement in my project,
can i use this code and implement in my prj. and distributed or republished.,
 

Thanks Regard,
Ramesh
AnswerRe: republishe codememberJevgenij Pankov8 Mar '12 - 22:03 
Dear Ramesh,
 
You can use this code in your projects as soon as it is under CPOL license.
 

Kind Regards,
Jevgenijs Pankovs
Questionthanksmemberhuseyinnn27 Feb '12 - 23:16 
very usefull for my project
QuestionStretched Title elementmemberjoe brockhaus22 Feb '12 - 8:57 
How to do this (without codebehind)?
 
I want to show a help icon just to the left of the Min/Res/Max buttons .. but the content of the Title element can't stretch the whole width.
Joe Brockhaus
Sogeti USA

QuestionModal dialog only first button workmemberDanilo Mendez Gamonal14 Feb '12 - 11:35 
Nice work!
I have a problem, in any modal dialog only one button work, inclusive in your online sample only work the OK button if you made copy of the OK button only the first one button works
QuestionMaximize/Minimize/Restore in IE 9 dont workmembervnadai10 Feb '12 - 2:53 
Hi friend,
 
First to congratulate you for the component. It is excellent.
It was the only one who found that really works, but I found a problem in Internet Explore version 9.
Is necessary various clicks in button Maximize/Minimize/Restore for works. And sometimes one click works. The problem is intermittent.
 
Do you have any idea about this ?
 
thanks
AnswerRe: Maximize/Minimize/Restore in IE 9 dont workmemberjoe brockhaus22 Feb '12 - 8:39 
If I understand you correctly, sometimes clicking those buttons doesn't do anything?
 
I've seen this also, but it usually has to do with my Browser's zoom setting.
Joe Brockhaus
Sogeti USA

QuestionProblem with maximized windowmembervenomAA7 Feb '12 - 11:43 
I'm maximizing a window when the host window opens and disable the resize, maximize and minimize buttons. In IE the window functions correctly, but when i try it in chrome, the window is not maximized and its only a tiny portion of the one in design. Other things like position of the window work ok. Only the maximize function is failing.
 
Any ideas why is this?
AnswerRe: Problem with maximized windowmembervenomAA27 Feb '12 - 12:39 
Actually i have been doing some further test and the floating windows does maximize IF I resize the window of the browser. Any ideas on it?
Questionwindow1.ShowModal() ... window2.Show() breaks modalitymemberjoe brockhaus20 Jan '12 - 10:35 
if you show a window as modal .. then show another window .. the modal window stays on top, but the other window(s) will be clickable and the overlay goes away
Joe Brockhaus
Sogeti USA

QuestionModal dialog - only first button works?memberMrPC19695 Jan '12 - 4:37 
Hi there,
Been a while since last posted, but now back on project using your controls.
 
Just using the sample app, show the ModalDialog.
The cancel button doesn't respond to Click event.
If you do click it (so it gets focus) you can then press space bar to invoke the click handler
 
Have tried using MvvmLight as well to bind ViewModel to modal dialog, but still getting the same behaviour
 
Any thoughts?
 
Cheers
Paul
 
Have been doing some work on extending your control,
1. IFloatingWindowController
FloatingWindowController : IFloatingWindowController
Abstraction of the show/Close methods for the Floating Window
2. BlacklightWindowController
see http://mightymeaty.members.winisp.net/blacklight.silverlight/[^] Interactive Controls|Drag Drop Panel
FloatingWindowHost defaults to use FloatingWindowController, but you can change to use another one.
 
This is still on-going, but 75% done.
 

New theme - Black.xaml - based on your black styling of the WindowWithChart
AnswerRe: Modal dialog - only first button works?memberjoe brockhaus20 Jan '12 - 10:31 
that dockpanel is slick.
 
i'm curious what cancel button you are talking about?
Joe Brockhaus
Sogeti USA

GeneralRe: Modal dialog - only first button works?memberMrPC196922 Jan '12 - 22:10 
It most certainly is very slick and I'm extending it as per details at bottom of OP
 
Go to the demo link
http://jevgenijpankov.heliocode.com/demo/FloatingWindowDemo.html[^]
 
Select OpenWindow|Modal Window
 
Click the Cancel button - it seems to get focus, but no mousedown event.
Spacebar does invoke it correctly
GeneralRe: Modal dialog - only first button works?memberjoe brockhaus22 Feb '12 - 8:36 
oh indeed weird.
Joe Brockhaus
Sogeti USA

QuestionFloatingWindow looks hazy in the FloatingWIndowHost [modified]memberjahedur.rahman27 Dec '11 - 23:44 
hi...this is really a very nice control and I am loving it. But I found that the FloatingWindows displayed in the FloatingWindowHost look very hazy and the fonts are not clear enough. Has anyone noticed this before?
 
Is there any workaround to make the FloatingWindows clear enough?
 
Thanks,
Jahedur Rahman

modified 28 Dec '11 - 5:52.

AnswerRe: FloatingWindow looks hazy in the FloatingWIndowHostmemberjoe brockhaus20 Jan '12 - 10:27 
If your browser's Zoom is set to something other than 100%, sometimes when rendered the SL looks fuzzy.
Joe Brockhaus
Sogeti USA

QuestionHow to increase the bootstrapButton heightmemberllongenberger1 Dec '11 - 6:47 
I've tried everyting I could think of (Changing the template, resizing after template is applied, recreating the style), but nothing seems to work. I'm clearly missing something on how you have constructed the iconbar, but can you share how to change the height of the bootstrapButton? Thanks in advance.
GeneralMy vote of 5memberdelibey19 Nov '11 - 13:50 
very usefull thx
BugNullReferenceException if FloatingWindows {get;} prior to OnApplyTemplatememberfel0nious8 Nov '11 - 4:34 
In my app we have the need to pop some windows automatically when it loads up.
 
In some cases, the app does not have focus when this happens, so the Visual Tree isn't created. (i.e. in a browser control inside a tab control without focus, or if you minimize the window prior to the app loading, etc.)
 
When the code inspects the FloatingWindows collection when these conditions are met, a NullReferenceException is thrown because hostCanvas is null, because OnApplyTemplate() has not yet been invoked.
 
Taking a clue from FloatingWindowHost.Add(FloatingWindow window) ... I added the following code to ensure the visual tree is built before returning the FloatingWindows collection (and hostCanvas).
 
(We inspect the collection before adding because some of our windows can only have one instance open at a time.)
 
        /// <summary>
        /// Gets the floating windows collection.
        /// </summary>
        /// <value>The floating windows collection.</value>
        public IEnumerable<FloatingWindow> FloatingWindows
        {
            get
            {
                // Guarantee that the visual tree of the control is complete
                if (!templateIsApplied)
                    templateIsApplied = ApplyTemplate(); 
 
                return hostCanvas.Children.OfType<FloatingWindow>(); 
            }
        }

SuggestionDefaultWindowStatememberfel0nious7 Nov '11 - 6:11 
I needed this functionality in my app - here's how I did it.
 
 
    <sfc:FloatingWindow 
        x:Class="MyFloatingWindow"
        
        DefaultWindowState"Maximized"
    />
    <!-- window content --> 
    </sfc:FloatingWindow>
 
 
 
        /// <summary>
        /// Gets or sets the default state of the window.
        /// </summary>
        /// <value>Current state of the window.</value>
        public WindowState DefaultWindowState { get; set; }
 
        /// <summary>
        /// This method is called every time a <see cref="FloatingWindow" /> is displayed.
        /// </summary>
        protected virtual void OnOpened()
        {
            // existing code
            if (!Focus())
            {
                // If the Focus() fails it means there is no focusable element in the window.
                // In this case we set IsTabStop to true to have the keyboard functionality
                IsTabStop = true;
                Focus();
            }
 
            // what I added
            this.Dispatcher.BeginInvoke(() =>
                {
                    switch (this.DefaultWindowState)
                    {
                        case WindowState.Normal:
                            this.RestoreWindow();
                            break;
                        case WindowState.Maximized:
                            this.MaximizeWindow();
                            break;
                        case WindowState.Minimized:
                            this.MinimizeWindow();
                            break;
                        default:
                            break;
                    }
 
                });
        }
 


QuestionWindow CenteringmemberChop_CZ2 Nov '11 - 8:22 
Hi,
 
I have the following scenario:
 
My Views are implemented as UserControls that are in turn wrapped into FloatingWindow (UserControl is set as content of the FloatingWindow).
I don't want to specify the Width and Height for the View but I want the FloatingWindow to scale its Width and Height accordingly to its content.
The FloatingWindow does that but I need to place the Window in the center of the FloatingWindowHost before the Window is beeing shown.
 
The problem is that I don't know the Width and Height of the View and I cannot use the ActualWidth and ActualHeight before the Window is rendered. (I don't know how to do that because both values has 0.0 value)
 
I have tried to modify following property without any luck
private Point CenteredWindowPosition
{
     get
     {
          //return new Point((Host.ActualWidth - ActualWidth) / 2, (Host.ActualHeight - ActualHeight) / 2); <---- doesn't work, values are 0.0
          return new Point((Host.ActualWidth - Width) / 2, (Host.ActualHeight - Height) / 2);// <--- doesn't work too, Width and Height is NaN
     }
}
 
Could someone please suggest me any solution?
 
Thank you!
AnswerRe: Window CenteringmemberJevgenij Pankov3 Nov '11 - 7:53 
Hi,
 
The problem is that before the window is rendered, the system doesn't know its actual size (it is zero) and cannot place it in the center of the host.
GeneralRe: Window CenteringmemberChop_CZ3 Nov '11 - 9:23 
Hi,
 
yes, I understand that.
Is there any way how to solve this?
 
I have tried to replace the Canvas, that is used as container for FloatingWindows, with Grid.
FloatingWindows were rendered correctly even when their size wasn't specified.
 
But other functions ("inertia move" for example) didn't work as they should...
 
Thank you, anyway.
GeneralRe: Window Centering [modified]memberfel0nious7 Nov '11 - 6:07 
Maybe grab the source and make the EnsureVisible method public/protected (depending on scope needed).
 
As for when to call this method .. in the least I assume it will need to be in/after OnOpened method.
-- If you need to call this method from outside the window, then maybe add an EventHandler called Opened to go along with the protected OnOpened.
-- Otherwise, in the codebehind of your control, override OnOpened (be sure to leave base.OnOpened(); first), and then add your call to center the window there.
 
In a larger sense, I'm not sure what your motivation is for centering windows .. but in my application, I have a need for setting a default WindowState Maximized for instance. I'm about to add a thread showing how I did this.

modified 28 Nov '11 - 10:55.

Newsnear-simultaneous window 'throw' offscreen while maximizing results in permanently lost window.memberfel0nious27 Oct '11 - 7:30 
I am probably only seeing this because I made it possible to double-click the titlebar to maximize .. and so these 2 actions can be done very nearly at the same time, but ..
 
Basically, I've thrown a window off-screen and maximized it (though it doesn't really maximize it because i can only assume the 2 animations conflict with one another). So, now there is a window off-screen and selecting it in the IconBar doesn't 'restore' it (because its 'previous' position is offscreen?)
 
Anyway .. instead of troubleshooting that rabbit hole, I'm going to implement a close button on the windowIcon.
 
I'll reply when I've got it worked out, but just wanted you to be aware of the above.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 16 May 2011
Article Copyright 2010 by Jevgenij Pankov
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid